Skip to content

Commit

Permalink
fix: Q:CONFIG syntax highlighting and completion
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Sep 19, 2024
1 parent 626107c commit b8a54c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion language-support/inline-jbang.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"patterns": [
{
"contentName": "meta.embedded.block.jbang",
"match": "^(//)(DEPS|JAVA|MAIN|FILES|SOURCES|PREVIEW|MODULE|DESCRIPTION|GAV|COMPILE_OPTIONS|JAVAC_OPTIONS|RUNTIME_OPTIONS|JAVA_OPTIONS|NATIVE_OPTIONS|REPOS|MANIFEST|CDS|KOTLIN|GROOVY|JAVAAGENT)\\s+(.*)$",
"match": "^(//)(DEPS|JAVA|MAIN|FILES|SOURCES|PREVIEW|MODULE|DESCRIPTION|GAV|COMPILE_OPTIONS|JAVAC_OPTIONS|RUNTIME_OPTIONS|JAVA_OPTIONS|NATIVE_OPTIONS|REPOS|MANIFEST|CDS|KOTLIN|GROOVY|JAVAAGENT|Q:CONFIG+)\\s+(.*)$",
"captures": {
"0":{
"name":"directive.jbang"
Expand Down
2 changes: 1 addition & 1 deletion src/JBangDirectives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const PREVIEW = new Directive("PREVIEW","Enable Java preview features", f
export const SOURCES = new Directive("SOURCES", "Pattern to include as JBang sources", true);
export const FILES = new Directive("FILES", "Mount files to build", true);
export const REPOS = new Directive("REPOS", "Repositories used by Jbang to resolve dependencies");
export const QUARKUS_CONFIG = new Directive("Q:CONFIG ", "Quarkus configuration property");
export const QUARKUS_CONFIG = new Directive("Q:CONFIG", "Quarkus configuration property");

//Special case
export const FILES_PREFIX = `${FILES.prefix()} `;
Expand Down
43 changes: 20 additions & 23 deletions src/completion/DirectivesCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const retriggerCompletion: Command = { command: 'editor.action.triggerSuggest',
const QUARKUS_DEP = new Directive("DEPS io.quarkus:quarkus",""); //pretend it's a directive

export class DirectivesCompletion implements CompletionParticipant {

applies(lineText: string, position: Position): boolean {
return lineText.startsWith('//') || position.character === 0;
}
Expand All @@ -31,7 +31,7 @@ export class DirectivesCompletion implements CompletionParticipant {
items.push(getCompletion(JAVA, range));
}
items.push(getCompletion(DEPS, range));

if (document.languageId === 'groovy' && !scanner.found(GROOVY)) {
items.push(getCompletion(GROOVY, range));
}
Expand All @@ -48,9 +48,9 @@ export class DirectivesCompletion implements CompletionParticipant {
if (!scanner.found(MAIN)) {
items.push(getCompletion(MAIN, range));
}

items.push(getCompletion(SOURCES, range));

items.push(getCompletion(FILES, range));

items.push(getCompletion(REPOS, range));
Expand Down Expand Up @@ -93,36 +93,33 @@ export class DirectivesCompletion implements CompletionParticipant {


class DirectiveScanner {

directives:Directive[] = [];

found(directive: Directive): boolean {
return this.directives.includes(directive);
}

scan(document: TextDocument) {
const checkedDirectives = [
JAVA, JAVAC_OPTIONS, COMPILE_OPTIONS, DESCRIPTION, CDS, GAV, JAVAAGENT, MANIFEST, JAVA_OPTIONS, RUNTIME_OPTIONS, NATIVE_OPTIONS, KOTLIN, GROOVY, MAIN, MODULE, PREVIEW, QUARKUS_DEP
];
const checkedDirectives = new Set([
JAVA, JAVAC_OPTIONS, COMPILE_OPTIONS, DESCRIPTION, CDS, GAV, JAVAAGENT, MANIFEST,
JAVA_OPTIONS, RUNTIME_OPTIONS, NATIVE_OPTIONS, KOTLIN, GROOVY, MAIN, MODULE, PREVIEW, QUARKUS_DEP
]);
const lines = document.getText().split(/\r?\n/);
for (let i = 0; i < lines.length && checkedDirectives.length > 0; i++) {
const line = lines[i];
let found;
for(let j = 0; j < checkedDirectives.length; j++) {
const directive = checkedDirectives[j];
if (directive.matches(line, true)) {
found = directive;
break;
}

for (const line of lines) {
if (checkedDirectives.size === 0) {
break;
}
if (found) {
this.directives.push(found);
const index = checkedDirectives.indexOf(found, 0);
if (index > -1) {
checkedDirectives.splice(index, 1);
for (const directive of checkedDirectives) {
const includeSpace = directive !== QUARKUS_DEP;//special case for Quarkus dependencies
if (directive.matches(line, includeSpace)) {
this.directives.push(directive);
checkedDirectives.delete(directive);
break;
}
}
}
}
}
}
function getCompletion(directive: Directive, range?: Range, command?: Command): CompletionItem {
Expand Down

0 comments on commit b8a54c1

Please sign in to comment.