mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
fix(ssh_config): Fix all argument completions
This commit is contained in:
parent
14e0be08a6
commit
9183a3f004
@ -81,7 +81,7 @@ func checkMatch(
|
|||||||
allEntry := allEntries[0]
|
allEntry := allEntries[0]
|
||||||
previousEntry := m.GetPreviousEntry(allEntry)
|
previousEntry := m.GetPreviousEntry(allEntry)
|
||||||
|
|
||||||
if previousEntry != nil && !utils.KeyExists(fields.MatchAllOptionAllowedPreviousOptions, previousEntry.Criteria.Type) {
|
if previousEntry != nil && !utils.KeyExists(fields.MatchAllArgumentAllowedPreviousOptions, previousEntry.Criteria.Type) {
|
||||||
errs = append(errs, common.LSPError{
|
errs = append(errs, common.LSPError{
|
||||||
Range: allEntry.LocationRange,
|
Range: allEntry.LocationRange,
|
||||||
Err: errors.New("'all' should either be the first entry or immediately follow 'final' or 'canonical'"),
|
Err: errors.New("'all' should either be the first entry or immediately follow 'final' or 'canonical'"),
|
||||||
|
@ -27,7 +27,7 @@ var MatchValueFieldMap = map[matchparser.MatchCriteriaType]docvalues.DeprecatedV
|
|||||||
matchparser.MatchCriteriaTypeLocalUser: MatchTypeLocalUserField,
|
matchparser.MatchCriteriaTypeLocalUser: MatchTypeLocalUserField,
|
||||||
}
|
}
|
||||||
|
|
||||||
var MatchAllOptionAllowedPreviousOptions = map[matchparser.MatchCriteriaType]struct{}{
|
var MatchAllArgumentAllowedPreviousOptions = map[matchparser.MatchCriteriaType]struct{}{
|
||||||
matchparser.MatchCriteriaTypeCanonical: {},
|
matchparser.MatchCriteriaTypeCanonical: {},
|
||||||
matchparser.MatchCriteriaTypeFinal: {},
|
matchparser.MatchCriteriaTypeFinal: {},
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
sshconfig "config-lsp/handlers/ssh_config"
|
sshconfig "config-lsp/handlers/ssh_config"
|
||||||
"config-lsp/handlers/ssh_config/fields"
|
"config-lsp/handlers/ssh_config/fields"
|
||||||
matchparser "config-lsp/handlers/ssh_config/match-parser"
|
matchparser "config-lsp/handlers/ssh_config/match-parser"
|
||||||
|
"config-lsp/utils"
|
||||||
|
|
||||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||||
)
|
)
|
||||||
@ -24,7 +25,21 @@ func getMatchCompletions(
|
|||||||
entry := match.GetEntryAtPosition(cursor)
|
entry := match.GetEntryAtPosition(cursor)
|
||||||
|
|
||||||
if entry == nil || entry.Criteria.ContainsPosition(cursor) {
|
if entry == nil || entry.Criteria.ContainsPosition(cursor) {
|
||||||
return getMatchCriteriaCompletions(), nil
|
completions := getMatchCriteriaCompletions()
|
||||||
|
|
||||||
|
var showAllArgument = true
|
||||||
|
|
||||||
|
previousEntry := match.GetPreviousEntryFromCursor(cursor)
|
||||||
|
|
||||||
|
if previousEntry != nil && !utils.KeyExists(fields.MatchAllArgumentAllowedPreviousOptions, previousEntry.Criteria.Type) {
|
||||||
|
showAllArgument = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if showAllArgument {
|
||||||
|
completions = append(completions, getMatchAllKeywordCompletion())
|
||||||
|
}
|
||||||
|
|
||||||
|
return completions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return getMatchValueCompletions(entry, cursor), nil
|
return getMatchValueCompletions(entry, cursor), nil
|
||||||
|
@ -53,6 +53,19 @@ func (m Match) GetPreviousEntry(e *MatchEntry) *MatchEntry {
|
|||||||
return m.Entries[index-1]
|
return m.Entries[index-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Match) GetPreviousEntryFromCursor(cursor common.CursorPosition) *MatchEntry {
|
||||||
|
entries := slices.Clone(m.Entries)
|
||||||
|
slices.Reverse(entries)
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
if entry.IsPositionAfterStart(cursor) {
|
||||||
|
return entry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (e MatchEntry) GetValueAtPosition(position common.Position) *MatchValue {
|
func (e MatchEntry) GetValueAtPosition(position common.Position) *MatchValue {
|
||||||
if e.Values == nil {
|
if e.Values == nil {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user