mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
fix: Improve applyEdit; Improvements
This commit is contained in:
parent
6e1d600659
commit
9bc931c686
@ -32,7 +32,7 @@
|
||||
pname = "github.com/Myzel394/config-lsp";
|
||||
version = "v0.0.1";
|
||||
src = ./server;
|
||||
vendorHash = "sha256-s+sjOVvqU20+mbEFKg+RCD+dhScqSatk9eseX2IioPI=";
|
||||
vendorHash = "sha256-s+sjOVvqU20+mbEFKg+RCD+dhScqSatk9eseX2IioPI";
|
||||
checkPhase = ''
|
||||
go test -v $(pwd)/...
|
||||
'';
|
||||
|
@ -6,8 +6,8 @@ import (
|
||||
)
|
||||
|
||||
func ClearDiagnostics(context *glsp.Context, uri protocol.DocumentUri) {
|
||||
context.Notify(
|
||||
"textDocument/publishDiagnostics",
|
||||
go context.Notify(
|
||||
protocol.ServerTextDocumentPublishDiagnostics,
|
||||
protocol.PublishDiagnosticsParams{
|
||||
URI: uri,
|
||||
Diagnostics: []protocol.Diagnostic{},
|
||||
@ -16,8 +16,8 @@ func ClearDiagnostics(context *glsp.Context, uri protocol.DocumentUri) {
|
||||
}
|
||||
|
||||
func SendDiagnostics(context *glsp.Context, uri protocol.DocumentUri, diagnostics []protocol.Diagnostic) {
|
||||
context.Notify(
|
||||
"textDocument/publishDiagnostics",
|
||||
go context.Notify(
|
||||
protocol.ServerTextDocumentPublishDiagnostics,
|
||||
protocol.PublishDiagnosticsParams{
|
||||
URI: uri,
|
||||
Diagnostics: diagnostics,
|
||||
|
@ -1,11 +1,8 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
"config-lsp/handlers/ssh_config/diagnostics"
|
||||
"config-lsp/handlers/ssh_config/fields"
|
||||
"fmt"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func analyzeValuesAreValid(
|
||||
@ -23,12 +20,12 @@ func analyzeValuesAreValid(
|
||||
continue
|
||||
}
|
||||
|
||||
ctx.diagnostics = append(ctx.diagnostics,
|
||||
protocol.Diagnostic{
|
||||
Range: option.Key.ToLSPRange(),
|
||||
Message: fmt.Sprintf("Unknown option: %s", option.Key.Value.Value),
|
||||
Severity: &common.SeverityError,
|
||||
},
|
||||
ctx.diagnostics = append(
|
||||
ctx.diagnostics,
|
||||
diagnostics.GenerateUnknownOption(
|
||||
option.Key.ToLSPRange(),
|
||||
option.Key.Value.Value,
|
||||
),
|
||||
)
|
||||
ctx.document.Indexes.UnknownOptions[info.Option.Start.Line] = info
|
||||
|
||||
|
19
server/handlers/ssh_config/diagnostics/diagnostics.go
Normal file
19
server/handlers/ssh_config/diagnostics/diagnostics.go
Normal file
@ -0,0 +1,19 @@
|
||||
package diagnostics
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
"fmt"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func GenerateUnknownOption(
|
||||
diagnosticRange protocol.Range,
|
||||
optionName string,
|
||||
) protocol.Diagnostic {
|
||||
return protocol.Diagnostic{
|
||||
Range: diagnosticRange,
|
||||
Message: fmt.Sprintf("Unknown option: %s", optionName),
|
||||
Severity: &common.SeverityError,
|
||||
}
|
||||
}
|
@ -98,14 +98,13 @@ func (args codeActionAddToUnknownArgs) RunCommand(d *sshconfig.SSHDocument) (*pr
|
||||
|
||||
rawOptionName := option.Key.Value.Raw
|
||||
optionName := addToUnknownOptionTemplate.Format(formatting.DefaultFormattingOptions, rawOptionName)
|
||||
label := fmt.Sprintf("Add %s to unknown options", option.Key.Key)
|
||||
|
||||
// We got everything, let's build the edit!
|
||||
if ignoreUnknownOption == nil {
|
||||
// Insert a completely new IgnoreUnknown option
|
||||
|
||||
if block == nil {
|
||||
// Global
|
||||
label := fmt.Sprintf("Add %s to unknown options", option.Key.Key)
|
||||
return &protocol.ApplyWorkspaceEditParams{
|
||||
Label: &label,
|
||||
Edit: protocol.WorkspaceEdit{
|
||||
@ -129,7 +128,7 @@ func (args codeActionAddToUnknownArgs) RunCommand(d *sshconfig.SSHDocument) (*pr
|
||||
},
|
||||
}, nil
|
||||
} else {
|
||||
label := fmt.Sprintf("Add %s to unknown options", option.Key.Key)
|
||||
// Block
|
||||
return &protocol.ApplyWorkspaceEditParams{
|
||||
Label: &label,
|
||||
Edit: protocol.WorkspaceEdit{
|
||||
@ -155,7 +154,6 @@ func (args codeActionAddToUnknownArgs) RunCommand(d *sshconfig.SSHDocument) (*pr
|
||||
}
|
||||
} else {
|
||||
// Append to the existing IgnoreUnknown option
|
||||
label := fmt.Sprintf("Add %s to unknown options", option.Key.Key)
|
||||
return &protocol.ApplyWorkspaceEditParams{
|
||||
Label: &label,
|
||||
Edit: protocol.WorkspaceEdit{
|
||||
|
@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
sshconfig "config-lsp/handlers/ssh_config"
|
||||
"config-lsp/handlers/ssh_config/diagnostics"
|
||||
"fmt"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
@ -33,9 +34,17 @@ func FetchCodeActions(
|
||||
},
|
||||
},
|
||||
}
|
||||
kind := protocol.CodeActionKindQuickFix
|
||||
codeAction := &protocol.CodeAction{
|
||||
Title: fmt.Sprintf("Add %s to unknown options", unknownOption.Option.Key.Key),
|
||||
Command: &command,
|
||||
Kind: &kind,
|
||||
Diagnostics: []protocol.Diagnostic{
|
||||
diagnostics.GenerateUnknownOption(
|
||||
unknownOption.Option.Key.ToLSPRange(),
|
||||
unknownOption.Option.Key.Value.Value,
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
return []protocol.CodeAction{
|
||||
|
@ -44,6 +44,19 @@ func initialize(context *glsp.Context, params *protocol.InitializeParams) (any,
|
||||
capabilities := lspHandler.CreateServerCapabilities()
|
||||
capabilities.TextDocumentSync = protocol.TextDocumentSyncKindFull
|
||||
capabilities.SignatureHelpProvider = &protocol.SignatureHelpOptions{}
|
||||
capabilities.ExecuteCommandProvider = &protocol.ExecuteCommandOptions{
|
||||
Commands: []string{
|
||||
"aliases.sendTestMail",
|
||||
|
||||
"hosts.inlineAliases",
|
||||
|
||||
"sshconfig.addToUnknown",
|
||||
|
||||
"wireguard.generatePrivateKey",
|
||||
"wireguard.generatePresharedKey",
|
||||
"wireguard.addKeepalive",
|
||||
},
|
||||
}
|
||||
|
||||
if (*params.Capabilities.TextDocument.Rename.PrepareSupport) == true {
|
||||
// Client supports rename preparation
|
||||
|
@ -54,26 +54,11 @@ func showParseError(
|
||||
uri protocol.DocumentUri,
|
||||
err common.ParseError,
|
||||
) {
|
||||
severity := protocol.DiagnosticSeverityError
|
||||
|
||||
common.SendDiagnostics(
|
||||
context,
|
||||
uri,
|
||||
[]protocol.Diagnostic{
|
||||
{
|
||||
Severity: &severity,
|
||||
context.Notify(
|
||||
"window/showMessage",
|
||||
protocol.ShowMessageParams{
|
||||
Type: protocol.MessageTypeError,
|
||||
Message: err.Err.Error(),
|
||||
Range: protocol.Range{
|
||||
Start: protocol.Position{
|
||||
Line: err.Line,
|
||||
Character: 0,
|
||||
},
|
||||
End: protocol.Position{
|
||||
Line: err.Line,
|
||||
Character: 99999,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -33,9 +33,11 @@ func WorkspaceExecuteCommand(context *glsp.Context, params *protocol.ExecuteComm
|
||||
return nil, err
|
||||
}
|
||||
|
||||
context.Notify(
|
||||
"workspace/applyEdit",
|
||||
// Seems like `context.Call` is blocking, so we move it to a goroutine
|
||||
go context.Call(
|
||||
protocol.ServerWorkspaceApplyEdit,
|
||||
edit,
|
||||
nil,
|
||||
)
|
||||
|
||||
return nil, nil
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as path from "path";
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import * as path from "path"
|
||||
import { ExtensionContext, workspace } from 'vscode';
|
||||
|
||||
import {
|
||||
Executable,
|
||||
@ -13,6 +13,7 @@ let client: LanguageClient;
|
||||
|
||||
export function activate(context: ExtensionContext) {
|
||||
console.info("config-lsp activated");
|
||||
const initOptions = workspace.getConfiguration('config-lsp');
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [
|
||||
{
|
||||
@ -26,7 +27,8 @@ export function activate(context: ExtensionContext) {
|
||||
language: 'yaml',
|
||||
pattern: "**/{config,sshconfig,sshd_config,sshdconfig,fstab,hosts,aliases}",
|
||||
},
|
||||
]
|
||||
],
|
||||
initializationOptions: initOptions,
|
||||
};
|
||||
|
||||
const path = getBundledPath();
|
||||
|
Loading…
x
Reference in New Issue
Block a user