- Notifications
You must be signed in to change notification settings - Fork 3
Improved suggestions for classes, variables and resources #86
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -2,8 +2,9 @@ import { Monaco } from '@monaco-editor/react'; | |
| import * as monaco from 'monaco-editor'; | ||
| import { MarkdownString } from 'monaco-editor/esm/vs/base/common/htmlContent'; | ||
| import { apiRequest } from '../../../api.ts'; | ||
| import { AssistCodeOutput } from '../../../api.types.ts'; | ||
| import {AssistCodeOutput, Suggestion} from '../../../api.types.ts'; | ||
| import { LANGUAGE_ID } from '../../groovy.ts'; | ||
| import {languages} from "monaco-editor/esm/vs/editor/editor.api" | ||
| | ||
| export function registerAemCodeCompletions(instance: Monaco) { | ||
| registerWordCompletion(instance); | ||
| | @@ -38,18 +39,14 @@ function registerWordCompletion(instance: Monaco) { | |
| }); | ||
| const assistance = response.data.data; | ||
| const suggestions = (assistance?.suggestions ?? []).map((suggestion) => ({ | ||
| label: suggestion.l ?? suggestion.it, | ||
| label: composeLabel(suggestion), | ||
| insertText: suggestion.it ?? suggestion.l, | ||
| insertTextRules: monacoInsertTextRules(suggestion.k), | ||
| kind: monacoKind(suggestion.k), | ||
| detail: suggestion.k, | ||
| documentation: new MarkdownString(suggestion.i), | ||
| range: new monaco.Range(position.lineNumber, wordAtPosition?.startColumn || position.column, position.lineNumber, wordAtPosition?.endColumn || position.column), | ||
| | ||
| // TODO below does not work, Monaco bug? (we want to prioritize exact class name matches) | ||
| // sortText: sortText(suggestion.v, wordText) | ||
| })); | ||
| | ||
| })) | ||
| return { suggestions: suggestions, incomplete: true }; | ||
| } catch (error) { | ||
| console.error('Code assistance error:', error); | ||
| | @@ -76,7 +73,7 @@ function registerResourceCompletion(instance: Monaco) { | |
| }); | ||
| const assistance = response.data.data; | ||
| const suggestions = (assistance?.suggestions ?? []).map((suggestion) => ({ | ||
| label: suggestion.it ?? suggestion.l, | ||
| label: composeLabel(suggestion), | ||
| insertText: removePathPrefix(path, suggestion.it ?? suggestion.l), // subtract path prefix | ||
| kind: monacoKind(suggestion.k), | ||
| detail: suggestion.k, | ||
| | @@ -154,12 +151,25 @@ function removePathPrefix(path: string, v: string) { | |
| return v; | ||
| } | ||
| | ||
| /* | ||
| function sortText(label: string, word: string): string { | ||
| const lastSegment = label.split('.').pop() || ''; | ||
| const isExactMatch = lastSegment === word; | ||
| const isPartialMatch = lastSegment.includes(word); | ||
| const score = (isExactMatch ? '0' : isPartialMatch ? '1' : '2'); | ||
| return score + "_" + label; | ||
| function composeLabel(suggestion: Suggestion) { | ||
| ||
| if (suggestion.k == "class") { | ||
kamil-orwat-vmltech marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| return { | ||
| label: suggestion.it ? suggestion.it.split('.').at(-1) : suggestion.l.split('.').at(-1), | ||
| description: suggestion.it ?? suggestion.l | ||
| } as languages.CompletionItemLabel | ||
| } else if (suggestion.k == "variable") { | ||
| return { | ||
| label: suggestion.it ? suggestion.it.split('.').at(-1) : suggestion.l.split('.').at(-1), | ||
| description: suggestion.i.replace("Type: ", "") | ||
| } as languages.CompletionItemLabel | ||
| } else if (suggestion.k == "resource") { | ||
| return { | ||
| label: suggestion.it ? suggestion.it.split("/").at(-1) : suggestion.l.split("/").at(-1), | ||
| description: suggestion.it | ||
| } as languages.CompletionItemLabel | ||
| } | ||
| return { | ||
| label: suggestion.l, | ||
| description: suggestion.it | ||
| } as languages.CompletionItemLabel | ||
| } | ||
| */ | ||
Uh oh!
There was an error while loading. Please reload this page.