Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 @@ -20,7 +20,8 @@ public class CodeRepository {
public @interface Config {
@AttributeDefinition(
name = "Class Links",
description = "Mapping of class prefixes to their corresponding documentation URLs in the format 'package=url'.")
description =
"Mapping of class prefixes to their corresponding documentation URLs in the format 'package=url'.")
String[] classLinks() default {
"com.vml.es.aem.acm.core=https://github.com/wttech/acm/blob/main/core/src/main/java",
"org.apache.sling.api=https://github.com/apache/sling-org-apache-sling-api/tree/master/src/main/java"
Expand Down
21 changes: 15 additions & 6 deletions ui.frontend/src/utils/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,23 @@ export type ExecutionOutput<E> = {

export type AssistCodeOutput = {
code: string;
suggestions: {
k: string; // kind
l: string; // label
it: string; // insert text
i: string; // info
}[];
suggestions: Suggestion[];
};

export enum SuggestionKind {
VARIABLE = 'variable',
RESOURCE = 'resource',
SNIPPET = 'snippet',
CLASS = 'class',
}

export type Suggestion = {
k: SuggestionKind; // kind
l: string; // label
it: string; // insert text
i: string; // info
}

export type SnippetOutput = {
list: Snippet[];
};
Expand Down
44 changes: 28 additions & 16 deletions ui.frontend/src/utils/monaco/groovy/completions/aem-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, SuggestionKind} 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);
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -154,12 +151,27 @@ 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) {
Copy link

Copilot AI May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The composeLabel function does not include a default case in its switch statement, which might lead to undefined behavior if an unrecognized suggestion kind is provided. Consider adding a default case to handle unexpected SuggestionKind values.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there won't be any 👍

switch (suggestion.k) {
case SuggestionKind.CLASS:
return {
label: suggestion.it ? suggestion.it.split('.').at(-1) : suggestion.l.split('.').at(-1),
description: suggestion.it ?? suggestion.l
} as languages.CompletionItemLabel
case SuggestionKind.VARIABLE:
return {
label: suggestion.it ? suggestion.it.split('.').at(-1) : suggestion.l.split('.').at(-1),
description: suggestion.i.replace("Type: ", "")
} as languages.CompletionItemLabel
case SuggestionKind.RESOURCE:
return {
label: suggestion.it ? suggestion.it.split("/").at(-1) : suggestion.l.split("/").at(-1),
description: suggestion.it
} as languages.CompletionItemLabel
case SuggestionKind.SNIPPET:
return {
label: suggestion.l,
description: suggestion.it
} as languages.CompletionItemLabel
}
}
*/