From 1d7e746545004a7f9fc67c090c816118b728cacd Mon Sep 17 00:00:00 2001 From: Myzel394 Date: Sun, 16 Mar 2025 14:56:42 +0100 Subject: [PATCH] fix: Improvements --- .github/workflows/pr-tests.yaml | 9 +++ flake.nix | 4 +- .../gitconfig/fields/nested-option.go | 78 ------------------- .../handlers/sshd_config/analyzer/options.go | 14 ++-- server/root-handler/common.go | 2 +- vs-code-extension/package.json | 2 +- vs-code-extension/tsconfig.tsbuildinfo | 1 + 7 files changed, 20 insertions(+), 90 deletions(-) delete mode 100644 server/handlers/gitconfig/fields/nested-option.go create mode 100644 vs-code-extension/tsconfig.tsbuildinfo diff --git a/.github/workflows/pr-tests.yaml b/.github/workflows/pr-tests.yaml index fa90407..e08fd03 100644 --- a/.github/workflows/pr-tests.yaml +++ b/.github/workflows/pr-tests.yaml @@ -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 + diff --git a/flake.nix b/flake.nix index 4ce0613..d90fac6 100644 --- a/flake.nix +++ b/flake.nix @@ -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)/... diff --git a/server/handlers/gitconfig/fields/nested-option.go b/server/handlers/gitconfig/fields/nested-option.go deleted file mode 100644 index f29b574..0000000 --- a/server/handlers/gitconfig/fields/nested-option.go +++ /dev/null @@ -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..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: - // - 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, - } -} diff --git a/server/handlers/sshd_config/analyzer/options.go b/server/handlers/sshd_config/analyzer/options.go index d8bd0aa..4fcd1d6 100644 --- a/server/handlers/sshd_config/analyzer/options.go +++ b/server/handlers/sshd_config/analyzer/options.go @@ -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 diff --git a/server/root-handler/common.go b/server/root-handler/common.go index 3ddbc36..5195aed 100644 --- a/server/root-handler/common.go +++ b/server/root-handler/common.go @@ -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 diff --git a/vs-code-extension/package.json b/vs-code-extension/package.json index 2078481..0651e0d 100644 --- a/vs-code-extension/package.json +++ b/vs-code-extension/package.json @@ -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" diff --git a/vs-code-extension/tsconfig.tsbuildinfo b/vs-code-extension/tsconfig.tsbuildinfo new file mode 100644 index 0000000..82c4d46 --- /dev/null +++ b/vs-code-extension/tsconfig.tsbuildinfo @@ -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"} \ No newline at end of file