fix: Improvements

This commit is contained in:
Myzel394 2025-03-16 14:56:42 +01:00
parent 7feb034a84
commit 1d7e746545
No known key found for this signature in database
GPG Key ID: B603E877F73D4ABB
7 changed files with 20 additions and 90 deletions

View File

@ -22,3 +22,12 @@ jobs:
- name: Build app
run: nix develop --command bash -c "cd server && go build"
- name: Build VS Code extension
run: nix build .#vs-code-extension
- name: Upload VS Code extension
uses: actions/upload-artifact@v3
with:
name: vs-code-extension
path: result/bin/vs-code-extension.vsix

View File

@ -23,7 +23,7 @@
"aarch64-windows"
] (system:
let
version = "0.1.4"; # CI:CD-VERSION
version = "0.2.0"; # CI:CD-VERSION
pkgs = import nixpkgs {
inherit system;
overlays = [
@ -42,7 +42,7 @@
pname = "github.com/Myzel394/config-lsp";
version = version;
src = ./server;
vendorHash = "sha256-eO1eY+2XuOCd/dKwgFtu05+bnn/Cv8ZbUIwRjCwJF+U=";
vendorHash = "sha256-ttr45N8i86mSJX9Scy/Cf+YlxU5wAKMVb0YhKg28JKM=";
ldflags = [ "-s" "-w" ];
checkPhase = ''
go test -v $(pwd)/...

View File

@ -1,78 +0,0 @@
package fields
import (
"config-lsp/common"
docvalues "config-lsp/doc-values"
"regexp"
)
// In the gitconfig, there are certain options that can be nested.
// This is okay with the usual config-lsp setup, but some option
// allow custom names, such as: diff.<driver>.binary
// To handle those options correctly, we store nested options separately.
//
// This struct may only be used to define the options.
type NestedOptionDeclaration struct {
// If true, the option is dynamic, like:
// <driver>
IsDynamic bool
// If set, `SubOption` is the next option
// If set, `Name` may not be set
Options map[NormalizedOptionName]NestedOptionDeclaration
// If set, `Name` is the documentation for the option
// If set, `SubOption` may not be set
Value *docvalues.DocumentationValue
}
func (n NestedOptionDeclaration) Parse(value string) (NestedOptionValue, error) {
return NestedOptionValue{}, nil
}
// This struct may be used to parse nested options and store their values.
// How this works:
// We declare the options using `NestedOptionDeclaration`. They are read-only
// Then:
// 1. The antlr parser parses the text
// 2. The keys are manually parsed into a `NestedOptionValue`
// 3. Later, during the analyzer phase, it checks the validity of the keys, and
// 4. Adds the `Name` to the `nestedOptionValueValue`
type NestedOptionValue struct {
Options []nestedOptionValueValue
}
type nestedOptionValueValue struct {
common.LocationRange
Option *NestedOptionDeclaration
// Values can't be quoted, so we don't need a `ParsedString`
Value string
}
var keyPartPattern = regexp.MustCompile(`[^.]+`)
func ParseNestedOptionToValue(
text string,
keyLocation common.LocationRange,
) NestedOptionValue {
indexes := keyPartPattern.FindAllIndex([]byte(text), -1)
options := make([]nestedOptionValueValue, 0)
for _, index := range indexes {
partText := text[index[0]:index[1]]
partRange := keyLocation
partRange.Start.Character = keyLocation.Start.Character + uint32(index[0])
partRange.End.Character = keyLocation.Start.Character + uint32(index[1])
options = append(
options,
nestedOptionValueValue{
LocationRange: partRange,
Value: partText,
},
)
}
return NestedOptionValue{
Options: options,
}
}

View File

@ -69,15 +69,13 @@ func checkOption(
// Since we don't know the option, we can't verify the value
return
} else {
// Check for values that are not allowed in Match blocks
if matchBlock != nil && !utils.KeyExists(fields.MatchAllowedOptions, option.Key.Key) {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: option.Key.ToLSPRange(),
Message: fmt.Sprintf("Option '%s' is not allowed in Match blocks", option.Key.Key),
Severity: &common.SeverityError,
})
}
} else if matchBlock != nil && !utils.KeyExists(fields.MatchAllowedOptions, option.Key.Key) {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: option.Key.ToLSPRange(),
Message: fmt.Sprintf("Option '%s' is not allowed in Match blocks", option.Key.Key),
Severity: &common.SeverityError,
})
}
///// Check if the value is valid

View File

@ -2,4 +2,4 @@ package roothandler
// The comment below at the end of the line is required for the CI:CD to work.
// Do not remove it
var Version = "0.1.4" // CI:CD-VERSION
var Version = "0.2.0" // CI:CD-VERSION

View File

@ -2,7 +2,7 @@
"name": "config-lsp",
"description": "Language Features (completions, diagnostics, etc.) for your config files: gitconfig, fstab, aliases, hosts, wireguard, ssh_config, sshd_config, and more to come!",
"author": "Myzel394",
"version": "0.1.4",
"version": "0.2.0",
"repository": {
"type": "git",
"url": "https://github.com/Myzel394/config-lsp"

View File

@ -0,0 +1 @@
{"root":["./src/extension.ts","./src/events/on-language-detected.ts","./src/events/on-language-undetectable.ts","./src/events/shared.ts","./src/events/types.ts"],"version":"5.7.3"}