Skip to content

Commit

Permalink
use correct document and filter experimental features (#458)
Browse files Browse the repository at this point in the history
* use correct document and filter experimental features

* calculate semantic tokens of correct document works now with both src and preview
* provide extended features not for all documents
  • Loading branch information
ChristopherHX authored Dec 1, 2024
1 parent 67a372f commit ab98200
Showing 1 changed file with 68 additions and 24 deletions.
92 changes: 68 additions & 24 deletions src/azure-pipelines-vscode-ext/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,24 @@ function activate(context) {
}
], {
provideDocumentSemanticTokens: async (doc, token) => {
var data = {enableSemTokens: true};
await expandAzurePipeline(false, null, null, null, () => {
}, null, () => {
}, null, null, null, true, true, null, null, data);
var semTokens = data.semTokens || new Uint32Array();
return new vscode.SemanticTokens(semTokens);
var obj;
var getSchema = () => {
try {
obj ??= jsYaml.load(doc.getText());
} catch {
obj = {};
}
return extractSchema(obj);
}
if(doc.languageId === "azure-pipelines" || doc.languageId === "yaml" && (obj = checkIsPipelineByContent(doc.getText()))) {
var data = {enableSemTokens: true};
await expandAzurePipeline(false, null, null, null, () => {
}, doc.uri.toString(), () => {
}, null, null, null, true, true, getSchema(), null, data);
var semTokens = data.semTokens || new Uint32Array();
return new vscode.SemanticTokens(semTokens);
}
return null;
}
}, new vscode.SemanticTokensLegend(["variable","parameter","function","property","constant","punctuation","string"], ["readonly","defaultLibrary","numeric"]));
context.subscriptions.push(semHighlight);
Expand All @@ -579,19 +591,31 @@ function activate(context) {
}
], {
provideCompletionItems: async (doc, pos, token, context) => {
var data = {autocompletelist: []};
await expandAzurePipeline(false, null, null, null, () => {
}, null, () => {
}, null, null, null, true, true, null, pos, data);
for(var item of data.autocompletelist) {
if(item.insertText && item.insertText.value) {
item.insertText = new vscode.SnippetString(item.insertText.value)
var obj;
var getSchema = () => {
try {
obj ??= jsYaml.load(doc.getText());
} catch {
obj = {};
}
if(item.documentation) {
item.documentation = new vscode.MarkdownString(item.documentation.value, item.supportThemeIcons)
return extractSchema(obj);
}
if(doc.languageId === "azure-pipelines" || doc.languageId === "yaml" && (obj = checkIsPipelineByContent(doc.getText()))) {
var data = {autocompletelist: []};
await expandAzurePipeline(false, null, null, null, () => {
}, doc.uri.toString(), () => {
}, null, null, null, true, true, getSchema(), pos, data);
for(var item of data.autocompletelist) {
if(item.insertText && item.insertText.value) {
item.insertText = new vscode.SnippetString(item.insertText.value)
}
if(item.documentation) {
item.documentation = new vscode.MarkdownString(item.documentation.value, item.supportThemeIcons)
}
}
return data.autocompletelist
}
return data.autocompletelist
return null;
}
});
context.subscriptions.push(autoComplete);
Expand All @@ -610,12 +634,23 @@ function activate(context) {
}
], {
provideHover: async (doc, pos, token) => {
var data = {autocompletelist: []};
await expandAzurePipeline(false, null, null, null, () => {
}, null, () => {
}, null, null, null, true, true, null, pos, data);
if(data.hover && data.hover.range && data.hover.content) {
return new vscode.Hover(new vscode.MarkdownString(data.hover.content, true), data.hover.range)
var obj;
var getSchema = () => {
try {
obj ??= jsYaml.load(doc.getText());
} catch {
obj = {};
}
return extractSchema(obj);
}
if(doc.languageId === "azure-pipelines" || doc.languageId === "yaml" && (obj = checkIsPipelineByContent(doc.getText()))) {
var data = {autocompletelist: []};
await expandAzurePipeline(false, null, null, null, () => {
}, doc.uri.toString(), () => {
}, null, null, null, true, true, getSchema(), pos, data);
if(data.hover && data.hover.range && data.hover.content) {
return new vscode.Hover(new vscode.MarkdownString(data.hover.content, true), data.hover.range)
}
}
return null;
}
Expand Down Expand Up @@ -680,9 +715,9 @@ function activate(context) {
return true;
}

var checkIsPipeline = () => {
var checkIsPipelineByContent = (content) => {
try {
var obj = jsYaml.load(vscode.window.activeTextEditor.document.getText());
var obj = jsYaml.load(content);
return ((obj.trigger || obj.pr || obj.resources && (obj.resources.builds instanceof Array || obj.resources.containers instanceof Array || obj.resources.pipelines instanceof Array || obj.resources.repositories instanceof Array || obj.resources.webhooks instanceof Array || obj.resources.packages instanceof Array) || obj.schedules instanceof Array || obj.lockBehavior instanceof String || obj.variables instanceof Object || obj.variables instanceof Array || obj.parameters instanceof Object || obj.parameters instanceof Array) && (obj.stages instanceof Array || obj.jobs instanceof Array || obj.steps instanceof Array)
|| obj.extends && obj.extends.template
|| obj.steps instanceof Array && obj.steps.find(x => x && (x.task || x.script !== undefined || x.bash !== undefined || x.pwsh !== undefined || x.powershell !== undefined || x.template !== undefined))
Expand All @@ -697,6 +732,15 @@ function activate(context) {
return null;
}

var checkIsPipeline = () => {
try {
return checkIsPipelineByContent(vscode.window.activeTextEditor.document.getText());
} catch {

}
return null;
}

var inProgress = false;
var lastLanguageChange = undefined;

Expand Down

0 comments on commit ab98200

Please sign in to comment.