Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SSH #20

Merged
merged 21 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fdb005a
feat(ssh_config): Add include functionality
Myzel394 Oct 14, 2024
4cdc916
feat(ssh_config): Do not handle includes if they contain tokens or en…
Myzel394 Oct 14, 2024
3caaf6a
feat(ssh_config): Add support for tokens check
Myzel394 Oct 14, 2024
b4aaa2c
feat(ssh_config): Add completions support for tokens
Myzel394 Oct 14, 2024
b0d8e80
fix(ssh_config): Improve include behavior
Myzel394 Oct 14, 2024
0e18169
feat(doc-value): Add respect quote value
Myzel394 Oct 15, 2024
f7f3845
fix(server): Improve quotes.go
Myzel394 Oct 15, 2024
43cc9e2
fix(server): Fix quotes issues
Myzel394 Oct 15, 2024
b1498ff
feat(sshd_config): Allow option keys to be case insensitive
Myzel394 Oct 15, 2024
ef737e1
feat(sshd_config): Add support for token completions
Myzel394 Oct 15, 2024
c463053
fix: apply linter
Myzel394 Oct 15, 2024
33a58a3
feat(sshd_config): Add analyzer support for tokens
Myzel394 Oct 15, 2024
b9b932d
fix(sshd_config): Add info about missing RoutingDomain documentation
Myzel394 Oct 15, 2024
c3d1ec3
fix(sshd_config): Use normalized option keys
Myzel394 Oct 16, 2024
9218771
fix(aliases): Improvements
Myzel394 Oct 16, 2024
d870beb
fix(server): Improve language detection
Myzel394 Oct 16, 2024
1fc847d
feat(ssh_config): Add support for signature help
Myzel394 Oct 16, 2024
994a561
fix(aliases): Fix signature help
Myzel394 Oct 16, 2024
55b55ac
feat(sshd_config): Add support for signature help
Myzel394 Oct 16, 2024
f690147
fix(sshd_config): Fix match option tag
Myzel394 Oct 16, 2024
407d24f
chore(docs): Update README.md
Myzel394 Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

| | diagnostics | `completion` | `hover` | `code-action` | `definition` | `rename` | `signature-help` |
|-------------|-------------|--------------|---------|---------------|--------------|----------|------------------|
| aliases | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| fstab | ✅ | ✅ | ✅ | ❓ | ❓ | ❓ | 🟡 |
| hosts | ✅ | ✅ | ✅ | ✅ | ❓ | ❓ | 🟡 |
| sshd_config | ✅ | ✅ | ✅ | ❓ | ✅ | ❓ | 🟡 |
| wireguard | ✅ | ✅ | ✅ | ✅ | ❓ | ❓ | 🟡 |
| aliases | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| fstab | ✅ | ✅ | ✅ | ❓ | ❓ | ❓ | 🟡 |
| hosts | ✅ | ✅ | ✅ | ✅ | ❓ | ❓ | 🟡 |
| ssh_config | ✅ | ✅ | ✅ | ✅ | ✅ | ❓ | ✅ |
| sshd_config | ✅ | ✅ | ✅ | ❓ | ✅ | ❓ | ✅ |
| wireguard | ✅ | ✅ | ✅ | ✅ | ❓ | ❓ | 🟡 |

✅ = Supported

🟡 = Will be supported, but not yet implemented

❓ = No idea what to implement here, please let me know if you have any ideas


37 changes: 34 additions & 3 deletions server/doc-values/value-array.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package docvalues
import (
"config-lsp/utils"
"fmt"
"regexp"
"strings"

protocol "github.com/tliron/glsp/protocol_3_16"
Expand Down Expand Up @@ -42,6 +43,9 @@ type ArrayValue struct {
// This is used to extract the value from the user input,
// because you may want to preprocess the value before checking for duplicates
DuplicatesExtractor *(func(string) string)

// If true, array ArrayValue ignores the `Separator` if it's within quotes
RespectQuotes bool
}

func (v ArrayValue) GetTypeDescription() []string {
Expand All @@ -53,9 +57,18 @@ func (v ArrayValue) GetTypeDescription() []string {
)
}

// TODO: Add support for quotes
func (v ArrayValue) DeprecatedCheckIsValid(value string) []*InvalidValue {
errors := []*InvalidValue{}
values := strings.Split(value, v.Separator)
var values []string

if v.RespectQuotes {
splitPattern := *regexp.MustCompile(fmt.Sprintf(`".+?"|[^%s]+`, v.Separator))

values = splitPattern.FindAllString(value, -1)
} else {
values = strings.Split(value, v.Separator)
}

if *v.DuplicatesExtractor != nil {
valuesOccurrences := utils.SliceToMap(
Expand Down Expand Up @@ -122,9 +135,27 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32)
MIN := uint32(0)
MAX := uint32(len(line) - 1)

var cursorSearchStart = cursor
var cursorSearchEnd = cursor

var start uint32
var end uint32

// Hello,world,how,are,you
// Hello,"world,how",are,you
if v.RespectQuotes {
quotes := utils.GetQuoteRanges(line)

if len(quotes) > 0 {
quote := quotes.GetQuoteForIndex(int(cursor))

if quote != nil {
cursorSearchStart = uint32(quote[0])
cursorSearchEnd = uint32(quote[1])
}
}
}

// hello,w[o]rld,and,more
// [h]ello,world
// hello,[w]orld
Expand All @@ -135,7 +166,7 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32)
relativePosition, found := utils.FindPreviousCharacter(
line,
v.Separator,
int(cursor),
int(cursorSearchStart),
)

if found {
Expand All @@ -151,7 +182,7 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32)
relativePosition, found = utils.FindNextCharacter(
line,
v.Separator,
int(start),
int(cursorSearchEnd),
)

if found {
Expand Down
4 changes: 2 additions & 2 deletions server/handlers/aliases/handlers/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ func GetCompletionsForEntry(
return completions, nil
}

switch (*value).(type) {
switch value.(type) {
case ast.AliasValueUser:
return getUserCompletions(
i,
excludedUsers,
), nil
case ast.AliasValueError:
errorValue := (*value).(ast.AliasValueError)
errorValue := value.(ast.AliasValueError)

isAtErrorCode := errorValue.Code == nil &&
errorValue.Location.IsPositionAfterStart(cursor) &&
Expand Down
4 changes: 2 additions & 2 deletions server/handlers/aliases/handlers/get-value.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func GetValueAtPosition(
position common.Position,
entry *ast.AliasEntry,
) *ast.AliasValueInterface {
) ast.AliasValueInterface {
if entry.Values == nil || len(entry.Values.Values) == 0 {
return nil
}
Expand All @@ -36,5 +36,5 @@ func GetValueAtPosition(
return nil
}

return &entry.Values.Values[index]
return entry.Values.Values[index]
}
4 changes: 2 additions & 2 deletions server/handlers/aliases/handlers/signature_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func GetRootSignatureHelp(
},
{
Label: []uint32{
uint32(len("<alias>:")),
uint32(len("<alias>:") + len("<value1>")),
uint32(len("<alias>: ")),
uint32(len("<alias>: ") + len("<value1>")),
},
Documentation: "A value to associate with the alias",
},
Expand Down
20 changes: 6 additions & 14 deletions server/handlers/aliases/lsp/text-document-completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,17 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa

entry := rawEntry.(*ast.AliasEntry)

if entry.Key == nil {
return handlers.GetAliasesCompletions(d.Indexes), nil
}

if entry.Key.Location.ContainsPosition(cursor) {
if entry.Key == nil || entry.Key.Location.ContainsPosition(cursor) {
return handlers.GetAliasesCompletions(d.Indexes), nil
}

if entry.Separator == nil && entry.Key.Location.IsPositionBeforeEnd(cursor) {
return nil, nil
}

if entry.Separator.IsPositionBeforeEnd(cursor) {
return handlers.GetCompletionsForEntry(
cursor,
entry,
d.Indexes,
)
}

return nil, nil
return handlers.GetCompletionsForEntry(
cursor,
entry,
d.Indexes,
)
}
2 changes: 1 addition & 1 deletion server/handlers/aliases/lsp/text-document-definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TextDocumentDefinition(context *glsp.Context, params *protocol.DefinitionPa

return handlers.GetDefinitionLocationForValue(
*d.Indexes,
*rawValue,
rawValue,
params.TextDocument.URI,
), nil
}
Expand Down
4 changes: 2 additions & 2 deletions server/handlers/aliases/lsp/text-document-hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ func TextDocumentHover(
}

contents := []string{}
contents = append(contents, handlers.GetAliasValueTypeInfo(*value)...)
contents = append(contents, handlers.GetAliasValueTypeInfo(value)...)
contents = append(contents, "")
contents = append(contents, "#### Value")
contents = append(contents, handlers.GetAliasValueHoverInfo(*document.Indexes, *value))
contents = append(contents, handlers.GetAliasValueHoverInfo(*document.Indexes, value))

text := strings.Join(contents, "\n")

Expand Down
4 changes: 2 additions & 2 deletions server/handlers/aliases/lsp/text-document-prepare-rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func TextDocumentPrepareRename(context *glsp.Context, params *protocol.PrepareRe
return nil, nil
}

switch (*rawValue).(type) {
switch rawValue.(type) {
case ast.AliasValueUser:
userValue := (*rawValue).(ast.AliasValueUser)
userValue := rawValue.(ast.AliasValueUser)

return userValue.Location.ToLSPRange(), nil
}
Expand Down
4 changes: 2 additions & 2 deletions server/handlers/aliases/lsp/text-document-rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func TextDocumentRename(context *glsp.Context, params *protocol.RenameParams) (*
return nil, nil
}

switch (*rawValue).(type) {
switch rawValue.(type) {
case ast.AliasValueUser:
userValue := (*rawValue).(ast.AliasValueUser)
userValue := rawValue.(ast.AliasValueUser)

changes := handlers.RenameAlias(
*d.Indexes,
Expand Down
10 changes: 4 additions & 6 deletions server/handlers/aliases/lsp/text-document-signature-help.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.Signature
document := aliases.DocumentParserMap[params.TextDocument.URI]

line := params.Position.Line
cursor := common.LSPCharacterAsCursorPosition(common.CursorToCharacterIndex(params.Position.Character))
cursor := common.LSPCharacterAsCursorPosition(params.Position.Character)

if _, found := document.Parser.CommentLines[line]; found {
// Comment
Expand All @@ -36,17 +36,15 @@ func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.Signature
if entry.Values != nil && entry.Values.Location.ContainsPosition(cursor) {
value := handlers.GetValueAtPosition(cursor, entry)

if value == nil {
if value == nil || value.GetAliasValue().Value == "" {
// For some reason, this does not really work,
// When we return all, and then a user value is entered
// and the `GetValueSignatureHelp` is called, still the old
// signatures with all signature are shown
// return handlers.GetAllValuesSignatureHelp(), nil

return nil, nil
return handlers.GetAllValuesSignatureHelp(), nil
}

return handlers.GetValueSignatureHelp(cursor, *value), nil
return handlers.GetValueSignatureHelp(cursor, value), nil
}

return nil, nil
Expand Down
20 changes: 20 additions & 0 deletions server/handlers/ssh_config/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,27 @@ func Analyze(

d.Indexes = i

analyzeIncludeValues(ctx)

if len(ctx.diagnostics) == 0 {
for _, include := range d.Indexes.Includes {
for _, value := range include.Values {
for _, path := range value.Paths {
_, err := parseFile(string(path))

if err != nil {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: value.LocationRange.ToLSPRange(),
Message: err.Error(),
})
}
}
}
}
}

analyzeValuesAreValid(ctx)
analyzeTokens(ctx)
analyzeIgnoreUnknownHasNoUnnecessary(ctx)
analyzeDependents(ctx)
analyzeBlocks(ctx)
Expand Down
Loading