本文整理汇总了TypeScript中vscode.languages.match方法的典型用法代码示例。如果您正苦于以下问题:TypeScript languages.match方法的具体用法?TypeScript languages.match怎么用?TypeScript languages.match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode.languages
的用法示例。
在下文中一共展示了languages.match方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: render
function render() {
if (!vscode.window.activeTextEditor) {
entry.hide();
return;
}
let document = vscode.window.activeTextEditor.document;
let status: Status;
if (projectStatus && vscode.languages.match(projectStatus.selector, document)) {
status = projectStatus;
} else if (defaultStatus.text && vscode.languages.match(defaultStatus.selector, document)) {
status = defaultStatus;
}
if (status) {
entry.text = status.text;
entry.command = status.command;
entry.color = status.color;
entry.show();
return;
}
entry.hide();
}
示例2: getLanguageEntry
/** Attempts to find the best-matching language entry for the language-id of the given document.
* @param the document to match
* @returns the best-matching language entry, or else `undefined` if none was found */
function getLanguageEntry(doc: vscode.TextDocument) : LanguageEntry {
const rankings = settings.substitutions
.map((entry) => ({rank: vscode.languages.match(entry.language, doc), entry: entry}))
.filter(score => score.rank > 0)
.sort((x,y) => (x.rank > y.rank) ? -1 : (x.rank==y.rank) ? 0 : 1);
let entry : LanguageEntry = rankings.length > 0
? Object.assign({}, rankings[0].entry)
: {
language: doc.languageId,
substitutions: [],
adjustCursorMovement: settings.adjustCursorMovement,
revealOn: settings.revealOn,
prettyCursor: settings.prettyCursor,
combineIdenticalScopes: true,
};
for(const language of additionalSubstitutions) {
if(vscode.languages.match(language.language, doc) > 0) {
entry.substitutions.push(...language.substitutions);
}
}
return entry;
}
示例3: applyConfigToTextEditor
function applyConfigToTextEditor(textEditor: vscode.TextEditor): any {
if (!textEditor) {
return;
};
let newOptions: vscode.TextEditorOptions = {
"insertSpaces": false,
"tabSize": 4
};
let defaultOptions: vscode.TextEditorOptions = {
"insertSpaces": Boolean(vscode.workspace.getConfiguration("editor").get("insertSpaces")),
"tabSize": Number(vscode.workspace.getConfiguration("editor").get("tabSize"))
};
if (vscode.languages.match(BSL_MODE, textEditor.document)) {
if (textEditor.options.insertSpaces === defaultOptions.insertSpaces
&& (textEditor.options.tabSize === defaultOptions.tabSize)) {
textEditor.options.insertSpaces = newOptions.insertSpaces;
textEditor.options.tabSize = newOptions.tabSize;
} else if (textEditor.options.insertSpaces === newOptions.insertSpaces && textEditor.options.tabSize === newOptions.tabSize) {
textEditor.options.insertSpaces = defaultOptions.insertSpaces;
textEditor.options.tabSize = defaultOptions.tabSize;
}
}
}
示例4:
didOpen: (document, next) => {
if (Languages.match(packageJsonFilter, document) || shouldBeValidated(document)) {
next(document);
syncedDocuments.set(document.uri.toString(), document);
return;
}
},
示例5:
(editor: vscode.TextEditor, edit: vscode.TextEditorEdit) => {
if (!vscode.languages.match(CLANG_MODE, editor.document)) {
vscode.window.showErrorMessage(`Current language is not C, C++ or Objective-C`);
return;
}
confViewer.show(editor.document);
}));
示例6: doBsllint
public doBsllint(textDocument: vscode.TextDocument) {
if (!vscode.languages.match(BSL_MODE, textDocument)) {
return;
}
let linterEnabled = Boolean(vscode.workspace.getConfiguration("language-1c-bsl").get("enableOneScriptLinter"));
let lintBSLFiles = Boolean(vscode.workspace.getConfiguration("language-1c-bsl").get("lintBSLFiles"));
let diagnostics: vscode.Diagnostic[] = [];
if (!linterEnabled) {
return;
}
let filename = textDocument.uri.fsPath;
if (filename.endsWith(".bsl") && !lintBSLFiles) {
return;
}
let args = this.args.slice();
args.push(filename);
let options = {
cwd: path.dirname(filename),
env: process.env
};
let result = "";
let phpcs = cp.spawn(this.commandId, args, options);
phpcs.stderr.on("data", function (buffer) {
result += buffer.toString();
});
phpcs.stdout.on("data", function (buffer) {
result += buffer.toString();
});
phpcs.on("close", () => {
try {
result = result.trim();
let lines = result.split(/\r?\n/);
let regex = /^\{Модуль\s+(.*)\s\/\s.*:\s+(\d+)\s+\/\s+(.*)\}/;
let vscodeDiagnosticArray = new Array<vscode.Diagnostic>();
for (let line in lines) {
let match = null;
match = lines[line].match(regex);
if (match !== null) {
let range = new vscode.Range(
new vscode.Position(match[2] - 1, 0),
new vscode.Position(+match[2] - 1, vscode.window.activeTextEditor.document.lineAt(match[2] - 1).text.length)
);
let vscodeDiagnostic = new vscode.Diagnostic(range, match[3], vscode.DiagnosticSeverity.Error);
vscodeDiagnosticArray.push(vscodeDiagnostic);
}
}
this.diagnosticCollection.set(textDocument.uri, vscodeDiagnosticArray);
if (vscodeDiagnosticArray.length !== 0 && vscode.workspace.rootPath === undefined) {
this.statusBarItem.text = vscodeDiagnosticArray.length === 0 ? "$(check) No Error" : "$(alert) " + vscodeDiagnosticArray.length + " Errors";
this.statusBarItem.show();
} else {
this.statusBarItem.hide();
};
} catch (e) {
console.error(e);
}
});
};
示例7: matchExtensionAsHtml
async function matchExtensionAsHtml(extension: string) {
const doc = await vscode.workspace.openTextDocument(
vscode.Uri.parse(`untitled:fake/path/doc.${extension}`)
);
expect(vscode.languages.match({ language: 'html' }, doc)).to.equal(
PERFECT_MATCH
);
}
示例8: onEditor
function onEditor(editor: vscode.TextEditor): void {
if (!editor
|| !vscode.languages.match(selector, editor.document)
|| !client.asAbsolutePath(editor.document.uri)) {
item.hide();
return;
}
const file = client.asAbsolutePath(editor.document.uri);
isOpen(file).then(value => {
if (!value) {
return;
}
return client.execute('projectInfo', { file, needFileNameList: true }).then(res => {
let {configFileName, fileNames} = res.body;
if (projectHinted[configFileName] === true) {
return;
}
if (fileNames.length > fileLimit) {
let largeRoots = computeLargeRoots(configFileName, fileNames).map(f => `'/${f}/'`).join(', ');
currentHint = {
message: largeRoots.length > 0
? localize('hintExclude', "For better performance exclude folders with many files, like: {0}", largeRoots)
: localize('hintExclude.generic', "For better performance exclude folders with many files."),
options: [{
title: localize('open', "Configure Excludes"),
execute: () => {
client.logTelemetry('js.hintProjectExcludes.accepted');
projectHinted[configFileName] = true;
item.hide();
return vscode.workspace.openTextDocument(configFileName)
.then(vscode.window.showTextDocument);
}
}]
};
item.tooltip = currentHint.message;
item.text = localize('large.label', "Configure Excludes");
item.tooltip = localize('hintExclude.tooltip', "For better performance exclude folders with many files.");
item.color = '#A5DF3B';
item.show();
client.logTelemetry('js.hintProjectExcludes');
} else {
item.hide();
}
});
}).catch(err => {
client.warn(err);
});
}
示例9:
context.subscriptions.push(vscode.commands.registerCommand('clang.showExecConf', () => {
let editor = vscode.window.activeTextEditor;
if (editor == null) {
vscode.window.showErrorMessage(`No active editor.`);
return;
}
if (!vscode.languages.match(CLANG_MODE, editor.document)) {
vscode.window.showErrorMessage(`Current language is not C, C++ or Objective-C`);
return;
}
confViewer.show(editor.document);
}));
示例10: updateStatusBarItemVisibility
public updateStatusBarItemVisibility(): void {
if (!this.canBeShown) {
return;
}
if (!window.activeTextEditor) {
this.statusBarItem.hide();
return;
}
if (languages.match(getDocumentFilter(), window.activeTextEditor.document)) {
this.statusBarItem.show();
} else {
this.statusBarItem.hide();
}
}