This commit is contained in:
Myzel394 2025-03-16 00:25:05 +01:00
parent 8350458ae5
commit 15471894d4
No known key found for this signature in database
GPG Key ID: B603E877F73D4ABB
4 changed files with 137 additions and 36 deletions

View File

@ -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
View 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)
})()

View 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,
}
}

View File

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