Skip to content

Commit 44080e9

Browse files
committed
Support for user tag
See redhat-developer/quarkus-ls#545 Signed-off-by: azerr <azerr@redhat.com>
1 parent a033cee commit 44080e9

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/qute/commands/registerCommands.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ export function registerVSCodeQuteCommands(context: ExtensionContext) {
2121
registerQuteValidationToggleCommand(context);
2222
context.subscriptions.push(
2323
workspace.onDidOpenTextDocument((document) => {
24-
if (!(document.uri.scheme === 'git')) {
25-
updateQuteLanguageId(context, document, true);
26-
}
24+
updateQuteLanguageId(context, document, true);
2725
})
2826
);
2927
// When extension is started, loop for each text documents which are opened to update their language ID.
@@ -202,7 +200,7 @@ async function checkQuteValidationFromExclusionContext(uri: Uri) {
202200
* - the button can be shown with eye-closed (when file is a Qute template file and validation is enabled).
203201
* - the button can be shown with eye-opened (when file is a Qute template file and validation is disabled)
204202
*/
205-
export async function synchronizeQuteValidationButton(editor: TextEditor) {
203+
export async function synchronizeQuteValidationButton(editor: TextEditor) {
206204
const document = editor?.document;
207205
if (!document) {
208206
return;
@@ -243,26 +241,40 @@ const LANGUAGE_MAP = new Map<string, string>([
243241
* @param document the text document.
244242
* @param onExtensionLoad if the user manually changed the language id.
245243
*/
246-
async function updateQuteLanguageId(context: ExtensionContext, document: TextDocument, onExtensionLoad: boolean) {
244+
async function updateQuteLanguageId(context: ExtensionContext, document: TextDocument, onExtensionLoad: boolean) {
245+
if (document.uri.scheme === 'git') {
246+
return;
247+
}
247248
const propertiesLanguageMismatch: QuteTemplateLanguageMismatch = QuteSettings.getQuteTemplatesLanguageMismatch();
248249
// Check if the setting is set to ignore or if the language ID is already set to Qute
249250
if (propertiesLanguageMismatch === QuteTemplateLanguageMismatch.ignore || document.languageId.startsWith('qute-')) {
250251
// Do nothing
251252
return;
252253
}
253-
const fileName: string = path.basename(document.fileName);
254-
if (document.fileName.includes(`resources${path.sep}templates${path.sep}`)) {
254+
if (isInTemplates(document)) {
255255
for (const extension of LANGUAGE_MAP.keys()) {
256256
if (path.extname(document.fileName) === extension) {
257257
const quteLanguageId = LANGUAGE_MAP.get(extension);
258-
258+
const fileName: string = path.basename(document.fileName);
259259
tryToForceLanguageId(context, document, fileName, propertiesLanguageMismatch, quteLanguageId, onExtensionLoad, QuteSettings.QUTE_OVERRIDE_LANGUAGE_ID, QuteSettings.QUTE_TEMPLATES_LANGUAGE_MISMATCH);
260260
break;
261261
}
262262
}
263263
}
264264
}
265265

266+
function isInTemplates(document: TextDocument): boolean {
267+
if (document.fileName.includes(`resources${path.sep}templates${path.sep}`)) {
268+
// HTML, etc file is included in src/main/resources/templates
269+
return true;
270+
}
271+
if (document.uri.scheme === 'jdt' && document.uri.path.startsWith(`/templates`)) {
272+
// HTML, etc file is included in a JAR in templates JAR entry
273+
return true;
274+
}
275+
return false;
276+
}
277+
266278
interface IConfiguration {
267279
workspaceConfiguration: WorkspaceConfiguration;
268280
target: ConfigurationTarget;

src/qute/languageServer/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export function connectToQuteLS(context: ExtensionContext, api: JavaExtensionAPI
7575
return quteLanguageClient.onReady().then(async () => {
7676
bindQuteRequest('qute/template/project');
7777
bindQuteRequest('qute/template/projectDataModel');
78+
bindQuteRequest('qute/template/userTags');
7879
bindQuteRequest('qute/template/javaTypes');
7980
bindQuteRequest('qute/template/resolvedJavaType');
8081
bindQuteRequest('qute/template/javaDefinition');

0 commit comments

Comments
 (0)