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

feat(language-server): add support for kebab-case completion #87

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ let tests =
"multiWord"
"MultiWord"
"multi_word"
"multi-word"
})
("Multi Word",
Some "m",
Expand All @@ -127,6 +128,7 @@ let tests =
"multiWord"
"MultiWord"
"multi_word"
"multi-word"
})
("multi word",
Some "m",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@ module One =
[ "firstTerm"
"FirstTerm"
"first_term"
"first-term"
"secondTerm"
"SecondTerm"
"second_term"
"second-term"
"thirdTerm"
"ThirdTerm"
"third_term" ]
"third_term"
"third-term" ]

module Two =
let expectedCompletionLabels =
seq
[ "word1"
"Word1"
"word_1"
"word-1"
"word2"
"Word2"
"word_2"
"word-2"
"word3"
"Word3"
"word_3" ]
"word_3"
"word-3" ]

let expectedCompletionLabelsPascal =
seq [ "Word1"; "WORD_1"; "Word2"; "WORD_2"; "Word3"; "WORD_3" ]
Expand Down
10 changes: 9 additions & 1 deletion src/language-server/Contextive.LanguageServer/Completion.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ let private (|UpperCase|_|) (ct: string) =
else
None

let private (|KebabCase|_|) (ct: string) =
if ct.Contains("-") && ct.ToLower() = ct then
Some()
else
None

let private termFilter = id

let private upper (s: string) = s.ToUpper()
Expand Down Expand Up @@ -117,13 +123,15 @@ let private candidateTermsToCaseMatchedCompletionData
let upperCase = ("", upper, upper)
let camelCase = ("", lower, title)
let pascalCase = ("", title, title)
let kebabCase = ("-", lower, lower)

let tokenCombinationGenerator =
match caseTemplate with
| Some(UpperCase) -> candidateTerms |> tokenCombinations [ upperCase; upperSnakeCase ]
| Some(PascalCase) -> candidateTerms |> tokenCombinations [ pascalCase; upperSnakeCase ]
| Some(CamelCase) -> candidateTerms |> tokenCombinations [ camelCase; snakeCase ]
| _ -> candidateTerms |> tokenCombinations [ camelCase; pascalCase; snakeCase ]
| Some(KebabCase) -> candidateTerms |> tokenCombinations [ kebabCase; snakeCase ]
| _ -> candidateTerms |> tokenCombinations [ camelCase; pascalCase; snakeCase; kebabCase ]

tokenCombinationGenerator term

Expand Down