mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
fix(server): Improvements
This commit is contained in:
parent
e4d7521a4c
commit
9f22689cac
@ -73,4 +73,3 @@ var APFSDocumentationEnums = []docvalues.EnumString{
|
|||||||
"This option indicates that in the course of the mount system call, the kernel should not follow any symlinks that may be present in the provided mount-on directory. This is the same as the -k option.",
|
"This option indicates that in the course of the mount system call, the kernel should not follow any symlinks that may be present in the provided mount-on directory. This is the same as the -k option.",
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
43
server/common/levenshtein.go
Normal file
43
server/common/levenshtein.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hbollon/go-edlib"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Find items that are similar to the given input.
|
||||||
|
// This is used to find typos & suggest the correct item.
|
||||||
|
// Once an item is found that has a Damerau-Levenshtein distance of 1, it is immediately returned.
|
||||||
|
// If not, then the next 2 items of similarity 2, or 3 items of similarity 3 are returned.
|
||||||
|
// If no items with similarity <= 3 are found, then an empty slice is returned.
|
||||||
|
func FindSimilarItems[T ~string](
|
||||||
|
input T,
|
||||||
|
items []T,
|
||||||
|
) []T {
|
||||||
|
itemsPerSimilarity := map[uint8][]T{
|
||||||
|
2: make([]T, 0, 2),
|
||||||
|
3: make([]T, 0, 3),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range items {
|
||||||
|
similarity := edlib.DamerauLevenshteinDistance(string(item), string(input))
|
||||||
|
|
||||||
|
switch similarity {
|
||||||
|
case 1:
|
||||||
|
return []T{item}
|
||||||
|
case 2:
|
||||||
|
itemsPerSimilarity[2] = append(itemsPerSimilarity[2], item)
|
||||||
|
|
||||||
|
if len(itemsPerSimilarity[2]) >= 2 {
|
||||||
|
return itemsPerSimilarity[2]
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
itemsPerSimilarity[3] = append(itemsPerSimilarity[3], item)
|
||||||
|
|
||||||
|
if len(itemsPerSimilarity[3]) >= 3 {
|
||||||
|
return itemsPerSimilarity[3]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return append(itemsPerSimilarity[2], itemsPerSimilarity[3]...)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user