mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
chore: Apply gofmt
This commit is contained in:
parent
403cc9a336
commit
1d55158fc8
@ -14,39 +14,43 @@ type Value interface {
|
||||
type EnumValue struct {
|
||||
Values []string
|
||||
}
|
||||
|
||||
func (v EnumValue) getTypeDescription() []string {
|
||||
lines := make([]string, len(v.Values) + 1)
|
||||
lines := make([]string, len(v.Values)+1)
|
||||
lines[0] = "Enum of:"
|
||||
|
||||
for index, value := range v.Values {
|
||||
lines[index + 1] += "\t* " + value
|
||||
lines[index+1] += "\t* " + value
|
||||
}
|
||||
|
||||
return lines
|
||||
}
|
||||
|
||||
type PositiveNumberValue struct {}
|
||||
type PositiveNumberValue struct{}
|
||||
|
||||
func (v PositiveNumberValue) getTypeDescription() []string {
|
||||
return []string{ "Positive number" }
|
||||
return []string{"Positive number"}
|
||||
}
|
||||
|
||||
type ArrayValue struct {
|
||||
SubValue Value
|
||||
Separator string
|
||||
SubValue Value
|
||||
Separator string
|
||||
AllowDuplicates bool
|
||||
}
|
||||
|
||||
func (v ArrayValue) getTypeDescription() []string {
|
||||
subValue := v.SubValue.(Value)
|
||||
|
||||
return append(
|
||||
[]string{ "An Array separated by " + v.Separator + " of:" },
|
||||
subValue.getTypeDescription()...
|
||||
[]string{"An Array separated by " + v.Separator + " of:"},
|
||||
subValue.getTypeDescription()...,
|
||||
)
|
||||
}
|
||||
|
||||
type OrValue struct {
|
||||
Values []Value
|
||||
}
|
||||
|
||||
func (v OrValue) getTypeDescription() []string {
|
||||
lines := make([]string, 0)
|
||||
|
||||
@ -66,31 +70,34 @@ func (v OrValue) getTypeDescription() []string {
|
||||
}
|
||||
|
||||
return append(
|
||||
[]string{ "One of:" },
|
||||
lines...
|
||||
[]string{"One of:"},
|
||||
lines...,
|
||||
)
|
||||
}
|
||||
|
||||
type StringValue struct {}
|
||||
type StringValue struct{}
|
||||
|
||||
func (v StringValue) getTypeDescription() []string {
|
||||
return []string{ "String" }
|
||||
return []string{"String"}
|
||||
}
|
||||
|
||||
type CustomValue struct {
|
||||
FetchValue func() Value
|
||||
}
|
||||
|
||||
func (v CustomValue) getTypeDescription() []string {
|
||||
return []string{ "Custom" }
|
||||
return []string{"Custom"}
|
||||
}
|
||||
|
||||
type Prefix struct {
|
||||
Prefix string
|
||||
Prefix string
|
||||
Meaning string
|
||||
}
|
||||
type PrefixWithMeaningValue struct {
|
||||
Prefixes []Prefix
|
||||
SubValue Value
|
||||
}
|
||||
|
||||
func (v PrefixWithMeaningValue) getTypeDescription() []string {
|
||||
subDescription := v.SubValue.getTypeDescription()
|
||||
|
||||
@ -100,23 +107,22 @@ func (v PrefixWithMeaningValue) getTypeDescription() []string {
|
||||
|
||||
return append(subDescription,
|
||||
append(
|
||||
[]string{ "The following prefixes are allowed:" },
|
||||
[]string{"The following prefixes are allowed:"},
|
||||
prefixDescription...,
|
||||
)...,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
type Option struct {
|
||||
Documentation string
|
||||
Value Value
|
||||
Value Value
|
||||
}
|
||||
|
||||
func GetDocumentation(o *Option) protocol.MarkupContent {
|
||||
typeDescription := strings.Join(o.Value.getTypeDescription(), "\n")
|
||||
|
||||
return protocol.MarkupContent{
|
||||
Kind: protocol.MarkupKindPlainText,
|
||||
Kind: protocol.MarkupKindPlainText,
|
||||
Value: "### Type\n" + typeDescription + "\n\n---\n\n### Documentation\n" + o.Documentation,
|
||||
}
|
||||
}
|
||||
@ -124,4 +130,3 @@ func GetDocumentation(o *Option) protocol.MarkupContent {
|
||||
func NewOption(documentation string, value Value) Option {
|
||||
return Option{documentation, value}
|
||||
}
|
||||
|
||||
|
@ -5,12 +5,13 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ParserError interface {}
|
||||
type ParserError interface{}
|
||||
|
||||
type OptionAlreadyExistsError struct {
|
||||
Option string
|
||||
Option string
|
||||
FoundOnLine uint32
|
||||
}
|
||||
|
||||
func (e OptionAlreadyExistsError) Error() string {
|
||||
return fmt.Sprintf("Option %s already exists", e.Option)
|
||||
}
|
||||
@ -18,6 +19,7 @@ func (e OptionAlreadyExistsError) Error() string {
|
||||
type OptionUnknownError struct {
|
||||
Option string
|
||||
}
|
||||
|
||||
func (e OptionUnknownError) Error() string {
|
||||
return fmt.Sprintf("Option '%s' does not exist", e.Option)
|
||||
}
|
||||
@ -25,20 +27,22 @@ func (e OptionUnknownError) Error() string {
|
||||
type MalformedLineError struct {
|
||||
Line string
|
||||
}
|
||||
|
||||
func (e MalformedLineError) Error() string {
|
||||
return fmt.Sprintf("Malformed line: %s", e.Line)
|
||||
}
|
||||
|
||||
type LineNotFoundError struct {}
|
||||
type LineNotFoundError struct{}
|
||||
|
||||
func (e LineNotFoundError) Error() string {
|
||||
return "Line not found"
|
||||
}
|
||||
|
||||
type ValueNotInEnumError struct {
|
||||
availableValues []string
|
||||
providedValue string
|
||||
providedValue string
|
||||
}
|
||||
|
||||
func (e ValueNotInEnumError) Error() string {
|
||||
return fmt.Sprint("'%s' is not valid. Select one from: %s", e.providedValue, strings.Join(e.availableValues, ","))
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,9 @@ import (
|
||||
)
|
||||
|
||||
type passwdInfo struct {
|
||||
Name string
|
||||
UID string
|
||||
GID string
|
||||
Name string
|
||||
UID string
|
||||
GID string
|
||||
HomePath string
|
||||
}
|
||||
|
||||
@ -36,9 +36,9 @@ func fetchPasswdInfo() ([]passwdInfo, error) {
|
||||
}
|
||||
|
||||
info := passwdInfo{
|
||||
Name: splitted[0],
|
||||
UID: splitted[2],
|
||||
GID: splitted[3],
|
||||
Name: splitted[0],
|
||||
UID: splitted[2],
|
||||
GID: splitted[3],
|
||||
HomePath: splitted[5],
|
||||
}
|
||||
|
||||
@ -50,7 +50,6 @@ func fetchPasswdInfo() ([]passwdInfo, error) {
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
|
||||
// UserValue returns a Value that fetches user names from /etc/passwd
|
||||
// if `separatorForMultiple` is not empty, it will return an ArrayValue
|
||||
func UserValue(separatorForMultiple string) Value {
|
||||
@ -73,11 +72,10 @@ func UserValue(separatorForMultiple string) Value {
|
||||
} else {
|
||||
return ArrayValue{
|
||||
AllowDuplicates: false,
|
||||
SubValue: enumValues,
|
||||
Separator: separatorForMultiple,
|
||||
SubValue: enumValues,
|
||||
Separator: separatorForMultiple,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ type SimpleConfigPosition struct {
|
||||
}
|
||||
|
||||
type SimpleConfigLine struct {
|
||||
Value string
|
||||
Value string
|
||||
Position SimpleConfigPosition
|
||||
}
|
||||
|
||||
@ -23,13 +23,13 @@ func (l SimpleConfigLine) IsCursorAtRootOption(cursor int) bool {
|
||||
}
|
||||
|
||||
type SimpleConfigOptions struct {
|
||||
Separator string
|
||||
IgnorePattern regexp.Regexp
|
||||
Separator string
|
||||
IgnorePattern regexp.Regexp
|
||||
AvailableOptions *map[string]Option
|
||||
}
|
||||
|
||||
type SimpleConfigParser struct {
|
||||
Lines map[string]SimpleConfigLine
|
||||
Lines map[string]SimpleConfigLine
|
||||
Options SimpleConfigOptions
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ func (p *SimpleConfigParser) AddLine(line string, lineNumber int) error {
|
||||
|
||||
if _, exists := p.Lines[option]; exists {
|
||||
return OptionAlreadyExistsError{
|
||||
Option: option,
|
||||
Option: option,
|
||||
FoundOnLine: uint32(lineNumber),
|
||||
}
|
||||
}
|
||||
@ -71,7 +71,7 @@ func (p *SimpleConfigParser) AddLine(line string, lineNumber int) error {
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (p *SimpleConfigParser) ReplaceOption(option string, value string) {
|
||||
@ -91,7 +91,7 @@ func (p *SimpleConfigParser) UpsertOption(option string, value string) {
|
||||
if _, exists := p.Lines[option]; exists {
|
||||
p.ReplaceOption(option, value)
|
||||
} else {
|
||||
p.AddLine(option + p.Options.Separator + value, len(p.Lines))
|
||||
p.AddLine(option+p.Options.Separator+value, len(p.Lines))
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ func (p *SimpleConfigParser) GetOption(option string) (SimpleConfigLine, error)
|
||||
Position: SimpleConfigPosition{
|
||||
Line: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
OptionUnknownError{
|
||||
Option: option,
|
||||
}
|
||||
@ -144,4 +144,3 @@ func (p *SimpleConfigParser) FindByLineNumber(lineNumber int) (string, SimpleCon
|
||||
|
||||
return "", SimpleConfigLine{Value: "", Position: SimpleConfigPosition{Line: 0}}, LineNotFoundError{}
|
||||
}
|
||||
|
||||
|
@ -28,4 +28,3 @@ func Map[T any, O any](values []T, f func(T) O) []O {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -10,47 +10,47 @@ import (
|
||||
)
|
||||
|
||||
func ClearDiagnostics(context *glsp.Context, uri protocol.DocumentUri) {
|
||||
context.Notify(
|
||||
"textDocument/publishDiagnostics",
|
||||
protocol.PublishDiagnosticsParams{
|
||||
URI: uri,
|
||||
Diagnostics: []protocol.Diagnostic{},
|
||||
},
|
||||
)
|
||||
context.Notify(
|
||||
"textDocument/publishDiagnostics",
|
||||
protocol.PublishDiagnosticsParams{
|
||||
URI: uri,
|
||||
Diagnostics: []protocol.Diagnostic{},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func SendDiagnosticsFromParserErrors(context *glsp.Context, uri protocol.DocumentUri, parserErrors []common.ParserError) {
|
||||
diagnosticErrors := make([]protocol.Diagnostic, 0)
|
||||
diagnosticErrors := make([]protocol.Diagnostic, 0)
|
||||
|
||||
for _, parserError := range parserErrors {
|
||||
switch parserError.(type) {
|
||||
case common.OptionAlreadyExistsError: {
|
||||
err := parserError.(common.OptionAlreadyExistsError)
|
||||
existingOption, _ := Parser.GetOption(err.Option)
|
||||
for _, parserError := range parserErrors {
|
||||
switch parserError.(type) {
|
||||
case common.OptionAlreadyExistsError:
|
||||
{
|
||||
err := parserError.(common.OptionAlreadyExistsError)
|
||||
existingOption, _ := Parser.GetOption(err.Option)
|
||||
|
||||
diagnosticErrors = append(diagnosticErrors, protocol.Diagnostic{
|
||||
Range: protocol.Range{
|
||||
Start: protocol.Position{
|
||||
Line: err.FoundOnLine,
|
||||
Character: 0,
|
||||
},
|
||||
End: protocol.Position{
|
||||
Line: err.FoundOnLine,
|
||||
Character: uint32(utf8.RuneCountInString(err.Option)),
|
||||
},
|
||||
},
|
||||
Message: fmt.Sprintf("Option '%s' has already been declared on line %v", err.Option, existingOption.Position.Line + 1),
|
||||
})
|
||||
diagnosticErrors = append(diagnosticErrors, protocol.Diagnostic{
|
||||
Range: protocol.Range{
|
||||
Start: protocol.Position{
|
||||
Line: err.FoundOnLine,
|
||||
Character: 0,
|
||||
},
|
||||
End: protocol.Position{
|
||||
Line: err.FoundOnLine,
|
||||
Character: uint32(utf8.RuneCountInString(err.Option)),
|
||||
},
|
||||
},
|
||||
Message: fmt.Sprintf("Option '%s' has already been declared on line %v", err.Option, existingOption.Position.Line+1),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.Notify(
|
||||
"textDocument/publishDiagnostics",
|
||||
protocol.PublishDiagnosticsParams{
|
||||
URI: uri,
|
||||
Diagnostics: diagnosticErrors,
|
||||
},
|
||||
)
|
||||
context.Notify(
|
||||
"textDocument/publishDiagnostics",
|
||||
protocol.PublishDiagnosticsParams{
|
||||
URI: uri,
|
||||
Diagnostics: diagnosticErrors,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,21 +6,20 @@ import (
|
||||
)
|
||||
|
||||
func createOpenSSHConfigParser() common.SimpleConfigParser {
|
||||
pattern, err := regexp.Compile(`^(?:#|\s*$)`)
|
||||
pattern, err := regexp.Compile(`^(?:#|\s*$)`)
|
||||
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return common.SimpleConfigParser{
|
||||
Lines: make(map[string]common.SimpleConfigLine),
|
||||
Options: common.SimpleConfigOptions{
|
||||
Separator: " ",
|
||||
IgnorePattern: *pattern,
|
||||
Separator: " ",
|
||||
IgnorePattern: *pattern,
|
||||
AvailableOptions: &Options,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var Parser = createOpenSSHConfigParser()
|
||||
|
||||
|
@ -39,9 +39,9 @@ func getRootCompletions() []protocol.CompletionItem {
|
||||
format := protocol.InsertTextFormatSnippet
|
||||
|
||||
completions[index] = protocol.CompletionItem{
|
||||
Label: label,
|
||||
Documentation: common.GetDocumentation(&option),
|
||||
InsertText: &insertText,
|
||||
Label: label,
|
||||
Documentation: common.GetDocumentation(&option),
|
||||
InsertText: &insertText,
|
||||
InsertTextFormat: &format,
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ func getCompletionsFromValue(value common.Value) []protocol.CompletionItem {
|
||||
textFormat := protocol.InsertTextFormatPlainText
|
||||
|
||||
completions[index] = protocol.CompletionItem{
|
||||
Label: value,
|
||||
Label: value,
|
||||
InsertTextFormat: &textFormat,
|
||||
}
|
||||
}
|
||||
@ -100,4 +100,3 @@ func getOptionCompletions(optionName string) []protocol.CompletionItem {
|
||||
|
||||
return completions
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,5 @@ func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
|
||||
ClearDiagnostics(context, params.TextDocument.URI)
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -22,5 +22,3 @@ func TextDocumentDidOpen(context *glsp.Context, params *protocol.DidOpenTextDocu
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
13
main.go
13
main.go
@ -25,12 +25,12 @@ func main() {
|
||||
commonlog.Configure(1, nil)
|
||||
|
||||
handler = protocol.Handler{
|
||||
Initialize: initialize,
|
||||
Initialized: initialized,
|
||||
Shutdown: shutdown,
|
||||
SetTrace: setTrace,
|
||||
TextDocumentDidOpen: openssh.TextDocumentDidOpen,
|
||||
TextDocumentDidChange: openssh.TextDocumentDidChange,
|
||||
Initialize: initialize,
|
||||
Initialized: initialized,
|
||||
Shutdown: shutdown,
|
||||
SetTrace: setTrace,
|
||||
TextDocumentDidOpen: openssh.TextDocumentDidOpen,
|
||||
TextDocumentDidChange: openssh.TextDocumentDidChange,
|
||||
TextDocumentCompletion: openssh.TextDocumentCompletion,
|
||||
}
|
||||
|
||||
@ -65,4 +65,3 @@ func setTrace(context *glsp.Context, params *protocol.SetTraceParams) error {
|
||||
protocol.SetTraceValue(params.Value)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user