-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: filter suggestions by node type (#999)
Closes #998 ### Summary of Changes * Don't suggest references to annotations/pipelines/schemas * Don't suggest named types pointing to type parameters of containing classes * Fix an issue in the fuzzy matcher: Now the first character of the query can match the first character of the label or the first character of any word transition (e.g. the `C` in `camelCase` or the `c` in `snake_case`).
- Loading branch information
1 parent
61e776b
commit 8d22e67
Showing
6 changed files
with
209 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/safe-ds-lang/src/language/lsp/safe-ds-fuzzy-matcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { DefaultFuzzyMatcher } from 'langium/lsp'; | ||
|
||
export class SafeDsFuzzyMatcher extends DefaultFuzzyMatcher { | ||
public override match(query: string, text: string): boolean { | ||
// Fixes a bug in the default fuzzy matcher. Can be removed once the bug is fixed upstream. | ||
if (query.length === 0) { | ||
return true; | ||
} | ||
|
||
// eslint-disable-next-line no-param-reassign | ||
let matchedFirstCharacter = false; | ||
let previous: number | undefined = undefined; | ||
let character = 0; | ||
const len = text.length; | ||
for (let i = 0; i < len; i++) { | ||
const strChar = text.charCodeAt(i); | ||
const testChar = query.charCodeAt(character); | ||
if (strChar === testChar || this.toUpperCharCode(strChar) === this.toUpperCharCode(testChar)) { | ||
matchedFirstCharacter ||= | ||
previous === undefined || // Beginning of word | ||
this.isWordTransition(previous, strChar); | ||
if (matchedFirstCharacter) { | ||
character++; | ||
} | ||
if (character === query.length) { | ||
return true; | ||
} | ||
} | ||
previous = strChar; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters