src/vs/editor/common/languageSelector.ts
159 LOC · 149 covered · 10 uncovered · 53 ranges · 1372 concepts · 28 introducers · 674 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
languageSelector.ts ×3
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IRelativePattern, match as matchGlobPattern } from '../../base/common/glob.js';
import { URI } from '../../base/common/uri.js';
import { normalize } from '../../base/common/path.js';
export interface LanguageFilter {
readonly language?: string;
readonly scheme?: string;
readonly pattern?: string | IRelativePattern;
readonly notebookType?: string;
/**
* This provider is implemented in the UI thread.
*/
readonly hasAccessToAllModels?: boolean;
readonly exclusive?: boolean;
/**
* This provider comes from a builtin extension.
*/
readonly isBuiltin?: boolean;
}
export type LanguageSelector = string | LanguageFilter | ReadonlyArray<string | LanguageFilter>;
export function score(selector: LanguageSelector | undefined, candidateUri: URI, candidateLanguage: string, candidateIsSynchronized: boolean, candidateNotebookUri: URI | undefined, candidateNotebookType: string | undefined): number {
if (Array.isArray(selector)) {
let ret = 0;
for (const filter of selector) {
const value = score(filter, candidateUri, candidateLanguage, candidateIsSynchronized, candidateNotebookUri, candidateNotebookType);
if (value === 10) {
}
ret = value;
}
}
return ret;
if (!candidateIsSynchronized) {
}
// short-hand notion, desugars to
// 'fooLang' -> { language: 'fooLang'}
// '*' -> { language: '*' }
if (selector === '*') {
}
// filter -> select accordingly, use defaults for scheme
const { language, pattern, scheme, hasAccessToAllModels, notebookType } = selector as LanguageFilter; // TODO: microsoft/TypeScript#42768
if (!candidateIsSynchronized && !hasAccessToAllModels) {
}
// selector targets a notebook -> use the notebook uri instead
// of the "normal" document uri.
if (notebookType && candidateNotebookUri) {
}
let ret = 0;
if (scheme) {
ret = 10;
} else if (scheme === '*') {
}
if (language) {
} else {
return 0;
}
if (notebookType) {
} else if (notebookType === '*' && candidateNotebookType !== undefined) {
languageSelector.ts ×4
}
if (pattern) {
if (typeof pattern === 'string') {
// to normalize this path first before passing it on
// because we will compare it against `Uri.fsPath`
// which uses platform specific separators.
// Refs: https://github.com/microsoft/vscode/issues/99938
normalizedPattern = { ...pattern, base: normalize(pattern.base) };
}
if (normalizedPattern === candidateUri.fsPath || matchGlobPattern(normalizedPattern, candidateUri.fsPath)) {
ret = 10;
} else {
}
return ret;
} else {
}
export function targetsNotebooks(selector: LanguageSelector): boolean {
if (typeof selector === 'string') {
return false;
} else if (Array.isArray(selector)) {
return selector.some(targetsNotebooks);
} else {
return !!(<LanguageFilter>selector).notebookType;
}
}
export function selectLanguageIds(selector: LanguageSelector, into: Set<string>): void {
into.add(selector);
} else if (Array.isArray(selector)) {
for (const item of selector) {
selectLanguageIds(item, into);
}
} else {
const language = (<LanguageFilter>selector).language;
if (language) {
into.add(language);
}
}
}