mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
fix: Improvements
This commit is contained in:
parent
7feb034a84
commit
1d7e746545
9
.github/workflows/pr-tests.yaml
vendored
9
.github/workflows/pr-tests.yaml
vendored
@ -22,3 +22,12 @@ jobs:
|
|||||||
- name: Build app
|
- name: Build app
|
||||||
run: nix develop --command bash -c "cd server && go build"
|
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
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
"aarch64-windows"
|
"aarch64-windows"
|
||||||
] (system:
|
] (system:
|
||||||
let
|
let
|
||||||
version = "0.1.4"; # CI:CD-VERSION
|
version = "0.2.0"; # CI:CD-VERSION
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
overlays = [
|
overlays = [
|
||||||
@ -42,7 +42,7 @@
|
|||||||
pname = "github.com/Myzel394/config-lsp";
|
pname = "github.com/Myzel394/config-lsp";
|
||||||
version = version;
|
version = version;
|
||||||
src = ./server;
|
src = ./server;
|
||||||
vendorHash = "sha256-eO1eY+2XuOCd/dKwgFtu05+bnn/Cv8ZbUIwRjCwJF+U=";
|
vendorHash = "sha256-ttr45N8i86mSJX9Scy/Cf+YlxU5wAKMVb0YhKg28JKM=";
|
||||||
ldflags = [ "-s" "-w" ];
|
ldflags = [ "-s" "-w" ];
|
||||||
checkPhase = ''
|
checkPhase = ''
|
||||||
go test -v $(pwd)/...
|
go test -v $(pwd)/...
|
||||||
|
@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
@ -69,15 +69,13 @@ func checkOption(
|
|||||||
|
|
||||||
// Since we don't know the option, we can't verify the value
|
// Since we don't know the option, we can't verify the value
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
// Check for values that are not allowed in Match blocks
|
// Check for values that are not allowed in Match blocks
|
||||||
if matchBlock != nil && !utils.KeyExists(fields.MatchAllowedOptions, option.Key.Key) {
|
} else if matchBlock != nil && !utils.KeyExists(fields.MatchAllowedOptions, option.Key.Key) {
|
||||||
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
||||||
Range: option.Key.ToLSPRange(),
|
Range: option.Key.ToLSPRange(),
|
||||||
Message: fmt.Sprintf("Option '%s' is not allowed in Match blocks", option.Key.Key),
|
Message: fmt.Sprintf("Option '%s' is not allowed in Match blocks", option.Key.Key),
|
||||||
Severity: &common.SeverityError,
|
Severity: &common.SeverityError,
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///// Check if the value is valid
|
///// Check if the value is valid
|
||||||
|
@ -2,4 +2,4 @@ package roothandler
|
|||||||
|
|
||||||
// The comment below at the end of the line is required for the CI:CD to work.
|
// The comment below at the end of the line is required for the CI:CD to work.
|
||||||
// Do not remove it
|
// Do not remove it
|
||||||
var Version = "0.1.4" // CI:CD-VERSION
|
var Version = "0.2.0" // CI:CD-VERSION
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "config-lsp",
|
"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!",
|
"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",
|
"author": "Myzel394",
|
||||||
"version": "0.1.4",
|
"version": "0.2.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/Myzel394/config-lsp"
|
"url": "https://github.com/Myzel394/config-lsp"
|
||||||
|
1
vs-code-extension/tsconfig.tsbuildinfo
Normal file
1
vs-code-extension/tsconfig.tsbuildinfo
Normal 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"}
|
Loading…
x
Reference in New Issue
Block a user