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
18
flake.nix
18
flake.nix
@ -28,15 +28,15 @@
|
|||||||
pkgs.go_1_22
|
pkgs.go_1_22
|
||||||
];
|
];
|
||||||
server = pkgs.buildGoModule {
|
server = pkgs.buildGoModule {
|
||||||
nativeBuildInputs = inputs;
|
nativeBuildInputs = inputs;
|
||||||
pname = "github.com/Myzel394/config-lsp";
|
pname = "github.com/Myzel394/config-lsp";
|
||||||
version = "v0.0.1";
|
version = "v0.0.1";
|
||||||
src = ./server;
|
src = ./server;
|
||||||
vendorHash = "sha256-s+sjOVvqU20+mbEFKg+RCD+dhScqSatk9eseX2IioPI=";
|
vendorHash = "sha256-s+sjOVvqU20+mbEFKg+RCD+dhScqSatk9eseX2IioPI";
|
||||||
checkPhase = ''
|
checkPhase = ''
|
||||||
go test -v $(pwd)/...
|
go test -v $(pwd)/...
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
packages = {
|
packages = {
|
||||||
default = server;
|
default = server;
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ClearDiagnostics(context *glsp.Context, uri protocol.DocumentUri) {
|
func ClearDiagnostics(context *glsp.Context, uri protocol.DocumentUri) {
|
||||||
context.Notify(
|
go context.Notify(
|
||||||
"textDocument/publishDiagnostics",
|
protocol.ServerTextDocumentPublishDiagnostics,
|
||||||
protocol.PublishDiagnosticsParams{
|
protocol.PublishDiagnosticsParams{
|
||||||
URI: uri,
|
URI: uri,
|
||||||
Diagnostics: []protocol.Diagnostic{},
|
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) {
|
func SendDiagnostics(context *glsp.Context, uri protocol.DocumentUri, diagnostics []protocol.Diagnostic) {
|
||||||
context.Notify(
|
go context.Notify(
|
||||||
"textDocument/publishDiagnostics",
|
protocol.ServerTextDocumentPublishDiagnostics,
|
||||||
protocol.PublishDiagnosticsParams{
|
protocol.PublishDiagnosticsParams{
|
||||||
URI: uri,
|
URI: uri,
|
||||||
Diagnostics: diagnostics,
|
Diagnostics: diagnostics,
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package analyzer
|
package analyzer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"config-lsp/common"
|
"config-lsp/handlers/ssh_config/diagnostics"
|
||||||
"config-lsp/handlers/ssh_config/fields"
|
"config-lsp/handlers/ssh_config/fields"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func analyzeValuesAreValid(
|
func analyzeValuesAreValid(
|
||||||
@ -23,12 +20,12 @@ func analyzeValuesAreValid(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.diagnostics = append(ctx.diagnostics,
|
ctx.diagnostics = append(
|
||||||
protocol.Diagnostic{
|
ctx.diagnostics,
|
||||||
Range: option.Key.ToLSPRange(),
|
diagnostics.GenerateUnknownOption(
|
||||||
Message: fmt.Sprintf("Unknown option: %s", option.Key.Value.Value),
|
option.Key.ToLSPRange(),
|
||||||
Severity: &common.SeverityError,
|
option.Key.Value.Value,
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
ctx.document.Indexes.UnknownOptions[info.Option.Start.Line] = info
|
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
|
rawOptionName := option.Key.Value.Raw
|
||||||
optionName := addToUnknownOptionTemplate.Format(formatting.DefaultFormattingOptions, rawOptionName)
|
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!
|
// We got everything, let's build the edit!
|
||||||
if ignoreUnknownOption == nil {
|
if ignoreUnknownOption == nil {
|
||||||
// Insert a completely new IgnoreUnknown option
|
// Insert a completely new IgnoreUnknown option
|
||||||
|
|
||||||
if block == nil {
|
if block == nil {
|
||||||
// Global
|
// Global
|
||||||
label := fmt.Sprintf("Add %s to unknown options", option.Key.Key)
|
|
||||||
return &protocol.ApplyWorkspaceEditParams{
|
return &protocol.ApplyWorkspaceEditParams{
|
||||||
Label: &label,
|
Label: &label,
|
||||||
Edit: protocol.WorkspaceEdit{
|
Edit: protocol.WorkspaceEdit{
|
||||||
@ -129,7 +128,7 @@ func (args codeActionAddToUnknownArgs) RunCommand(d *sshconfig.SSHDocument) (*pr
|
|||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
} else {
|
} else {
|
||||||
label := fmt.Sprintf("Add %s to unknown options", option.Key.Key)
|
// Block
|
||||||
return &protocol.ApplyWorkspaceEditParams{
|
return &protocol.ApplyWorkspaceEditParams{
|
||||||
Label: &label,
|
Label: &label,
|
||||||
Edit: protocol.WorkspaceEdit{
|
Edit: protocol.WorkspaceEdit{
|
||||||
@ -155,7 +154,6 @@ func (args codeActionAddToUnknownArgs) RunCommand(d *sshconfig.SSHDocument) (*pr
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Append to the existing IgnoreUnknown option
|
// Append to the existing IgnoreUnknown option
|
||||||
label := fmt.Sprintf("Add %s to unknown options", option.Key.Key)
|
|
||||||
return &protocol.ApplyWorkspaceEditParams{
|
return &protocol.ApplyWorkspaceEditParams{
|
||||||
Label: &label,
|
Label: &label,
|
||||||
Edit: protocol.WorkspaceEdit{
|
Edit: protocol.WorkspaceEdit{
|
||||||
|
@ -2,6 +2,7 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
sshconfig "config-lsp/handlers/ssh_config"
|
sshconfig "config-lsp/handlers/ssh_config"
|
||||||
|
"config-lsp/handlers/ssh_config/diagnostics"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||||
@ -33,9 +34,17 @@ func FetchCodeActions(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
kind := protocol.CodeActionKindQuickFix
|
||||||
codeAction := &protocol.CodeAction{
|
codeAction := &protocol.CodeAction{
|
||||||
Title: fmt.Sprintf("Add %s to unknown options", unknownOption.Option.Key.Key),
|
Title: fmt.Sprintf("Add %s to unknown options", unknownOption.Option.Key.Key),
|
||||||
Command: &command,
|
Command: &command,
|
||||||
|
Kind: &kind,
|
||||||
|
Diagnostics: []protocol.Diagnostic{
|
||||||
|
diagnostics.GenerateUnknownOption(
|
||||||
|
unknownOption.Option.Key.ToLSPRange(),
|
||||||
|
unknownOption.Option.Key.Value.Value,
|
||||||
|
),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return []protocol.CodeAction{
|
return []protocol.CodeAction{
|
||||||
|
@ -44,6 +44,19 @@ func initialize(context *glsp.Context, params *protocol.InitializeParams) (any,
|
|||||||
capabilities := lspHandler.CreateServerCapabilities()
|
capabilities := lspHandler.CreateServerCapabilities()
|
||||||
capabilities.TextDocumentSync = protocol.TextDocumentSyncKindFull
|
capabilities.TextDocumentSync = protocol.TextDocumentSyncKindFull
|
||||||
capabilities.SignatureHelpProvider = &protocol.SignatureHelpOptions{}
|
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 {
|
if (*params.Capabilities.TextDocument.Rename.PrepareSupport) == true {
|
||||||
// Client supports rename preparation
|
// Client supports rename preparation
|
||||||
|
@ -54,26 +54,11 @@ func showParseError(
|
|||||||
uri protocol.DocumentUri,
|
uri protocol.DocumentUri,
|
||||||
err common.ParseError,
|
err common.ParseError,
|
||||||
) {
|
) {
|
||||||
severity := protocol.DiagnosticSeverityError
|
context.Notify(
|
||||||
|
"window/showMessage",
|
||||||
common.SendDiagnostics(
|
protocol.ShowMessageParams{
|
||||||
context,
|
Type: protocol.MessageTypeError,
|
||||||
uri,
|
Message: err.Err.Error(),
|
||||||
[]protocol.Diagnostic{
|
|
||||||
{
|
|
||||||
Severity: &severity,
|
|
||||||
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Notify(
|
// Seems like `context.Call` is blocking, so we move it to a goroutine
|
||||||
"workspace/applyEdit",
|
go context.Call(
|
||||||
|
protocol.ServerWorkspaceApplyEdit,
|
||||||
edit,
|
edit,
|
||||||
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import * as path from "path";
|
import * as path from "path"
|
||||||
import { ExtensionContext } from 'vscode';
|
import { ExtensionContext, workspace } from 'vscode';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Executable,
|
Executable,
|
||||||
LanguageClient,
|
LanguageClient,
|
||||||
type LanguageClientOptions,
|
type LanguageClientOptions,
|
||||||
type ServerOptions,
|
type ServerOptions,
|
||||||
@ -12,7 +12,8 @@ const IS_DEBUG = process.env.VSCODE_DEBUG_MODE === 'true' || process.env.NODE_EN
|
|||||||
let client: LanguageClient;
|
let client: LanguageClient;
|
||||||
|
|
||||||
export function activate(context: ExtensionContext) {
|
export function activate(context: ExtensionContext) {
|
||||||
console.info("config-lsp activated");
|
console.info("config-lsp activated");
|
||||||
|
const initOptions = workspace.getConfiguration('config-lsp');
|
||||||
const clientOptions: LanguageClientOptions = {
|
const clientOptions: LanguageClientOptions = {
|
||||||
documentSelector: [
|
documentSelector: [
|
||||||
{
|
{
|
||||||
@ -26,11 +27,12 @@ export function activate(context: ExtensionContext) {
|
|||||||
language: 'yaml',
|
language: 'yaml',
|
||||||
pattern: "**/{config,sshconfig,sshd_config,sshdconfig,fstab,hosts,aliases}",
|
pattern: "**/{config,sshconfig,sshd_config,sshdconfig,fstab,hosts,aliases}",
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
|
initializationOptions: initOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
const path = getBundledPath();
|
const path = getBundledPath();
|
||||||
console.info(`Found config-lsp path at ${path}`);
|
console.info(`Found config-lsp path at ${path}`);
|
||||||
const run: Executable = {
|
const run: Executable = {
|
||||||
command: getBundledPath(),
|
command: getBundledPath(),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user