mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
fix: Fix
This commit is contained in:
parent
8350458ae5
commit
15471894d4
@ -6,7 +6,10 @@ import (
|
||||
)
|
||||
|
||||
func ClearDiagnostics(context *glsp.Context, uri protocol.DocumentUri) {
|
||||
go context.Notify(
|
||||
// Diagnostics are sent synchronously, as sending them async
|
||||
// could result in a race condition when we send diagnostics
|
||||
// to the client.
|
||||
context.Notify(
|
||||
protocol.ServerTextDocumentPublishDiagnostics,
|
||||
protocol.PublishDiagnosticsParams{
|
||||
URI: uri,
|
||||
|
27
server/fetch_tags.js
Normal file
27
server/fetch_tags.js
Normal file
@ -0,0 +1,27 @@
|
||||
// Creates a JSON object in the form of:
|
||||
// {
|
||||
// [<Option name>]: documentation
|
||||
// }
|
||||
//
|
||||
// Searches for <dl> elements with <dt> and <dd> children based
|
||||
// on the currently selected element in the Elements tab of the
|
||||
|
||||
(() => {
|
||||
const content = {}
|
||||
let currentOption = ""
|
||||
|
||||
const $elements = $0.querySelectorAll(":scope > dt,dd")
|
||||
|
||||
for (const $element of $elements) {
|
||||
switch ($element.tagName) {
|
||||
case "DT":
|
||||
currentOption = $element.textContent.trim()
|
||||
break
|
||||
case "DD":
|
||||
content[currentOption] = $element.textContent.trim()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
console.log(content)
|
||||
})()
|
78
server/handlers/gitconfig/fields/nested-option.go
Normal file
78
server/handlers/gitconfig/fields/nested-option.go
Normal file
@ -0,0 +1,78 @@
|
||||
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,
|
||||
}
|
||||
}
|
@ -18,6 +18,11 @@ func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
content := params.ContentChanges[0].(protocol.TextDocumentContentChangeEventWhole).Text
|
||||
|
||||
if _, found := shared.OpenedFiles[params.TextDocument.URI]; !found {
|
||||
// The file couldn't be initialized when opening it,
|
||||
// so we will try it again here
|
||||
|
||||
newLanguage, err := initFile(
|
||||
context,
|
||||
content,
|
||||
@ -45,19 +50,7 @@ func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
|
||||
},
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case shared.LanguageFstab:
|
||||
return fstab.TextDocumentDidOpen(context, params)
|
||||
case shared.LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentDidOpen(context, params)
|
||||
case shared.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentDidOpen(context, params)
|
||||
case shared.LanguageWireguard:
|
||||
return wireguard.TextDocumentDidOpen(context, params)
|
||||
case shared.LanguageHosts:
|
||||
return hosts.TextDocumentDidOpen(context, params)
|
||||
case shared.LanguageAliases:
|
||||
return aliases.TextDocumentDidOpen(context, params)
|
||||
return TextDocumentDidOpen(context, params)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user