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) {
|
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.ServerTextDocumentPublishDiagnostics,
|
||||||
protocol.PublishDiagnosticsParams{
|
protocol.PublishDiagnosticsParams{
|
||||||
URI: uri,
|
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,46 +18,39 @@ func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
|
|||||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||||
|
|
||||||
content := params.ContentChanges[0].(protocol.TextDocumentContentChangeEventWhole).Text
|
content := params.ContentChanges[0].(protocol.TextDocumentContentChangeEventWhole).Text
|
||||||
newLanguage, err := initFile(
|
|
||||||
context,
|
|
||||||
content,
|
|
||||||
params.TextDocument.URI,
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
if _, found := shared.OpenedFiles[params.TextDocument.URI]; !found {
|
||||||
if common.ServerOptions.NoUndetectableErrors {
|
// The file couldn't be initialized when opening it,
|
||||||
return nil
|
// so we will try it again here
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if *newLanguage != *language {
|
newLanguage, err := initFile(
|
||||||
language = newLanguage
|
context,
|
||||||
|
content,
|
||||||
|
params.TextDocument.URI,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
|
||||||
params := &protocol.DidOpenTextDocumentParams{
|
if err != nil {
|
||||||
TextDocument: protocol.TextDocumentItem{
|
if common.ServerOptions.NoUndetectableErrors {
|
||||||
URI: params.TextDocument.URI,
|
return nil
|
||||||
Text: content,
|
} else {
|
||||||
Version: params.TextDocument.Version,
|
return err
|
||||||
LanguageID: string(*language),
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch *language {
|
if *newLanguage != *language {
|
||||||
case shared.LanguageFstab:
|
language = newLanguage
|
||||||
return fstab.TextDocumentDidOpen(context, params)
|
|
||||||
case shared.LanguageSSHDConfig:
|
params := &protocol.DidOpenTextDocumentParams{
|
||||||
return sshdconfig.TextDocumentDidOpen(context, params)
|
TextDocument: protocol.TextDocumentItem{
|
||||||
case shared.LanguageSSHConfig:
|
URI: params.TextDocument.URI,
|
||||||
return sshconfig.TextDocumentDidOpen(context, params)
|
Text: content,
|
||||||
case shared.LanguageWireguard:
|
Version: params.TextDocument.Version,
|
||||||
return wireguard.TextDocumentDidOpen(context, params)
|
LanguageID: string(*language),
|
||||||
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