未验证 提交 8a5ffbb0 编写于 作者: M Matt Bierner 提交者: GitHub

Mark DocumentSelector as readonly (#109212)

This change:

- Make  `DocumentSelector` use a readonly array
- Updates all properties of `DocumentFilter` to be readonly

`DocumentSelector` is used as a parameter in our provider APIs and does not need to be mutable. This change lets extensions pass in readonly values for the selector
上级 cfe2fd1a
......@@ -9,10 +9,10 @@ export interface DocumentSelector {
/**
* Selector for files which only require a basic syntax server.
*/
readonly syntax: vscode.DocumentFilter[];
readonly syntax: readonly vscode.DocumentFilter[];
/**
* Selector for files which require semantic server support.
*/
readonly semantic: vscode.DocumentFilter[];
readonly semantic: readonly vscode.DocumentFilter[];
}
......@@ -545,6 +545,8 @@ export function mapArrayOrNot<T, U>(items: T | T[], fn: (_: T) => U): U | U[] {
fn(items);
}
export function asArray<T>(x: T | T[]): T[];
export function asArray<T>(x: T | readonly T[]): readonly T[];
export function asArray<T>(x: T | T[]): T[] {
return Array.isArray(x) ? x : [x];
}
......
......@@ -8,17 +8,17 @@ import { URI } from 'vs/base/common/uri'; // TODO@Alex
import { normalize } from 'vs/base/common/path';
export interface LanguageFilter {
language?: string;
scheme?: string;
pattern?: string | IRelativePattern;
readonly language?: string;
readonly scheme?: string;
readonly pattern?: string | IRelativePattern;
/**
* This provider is implemented in the UI thread.
*/
hasAccessToAllModels?: boolean;
exclusive?: boolean;
readonly hasAccessToAllModels?: boolean;
readonly exclusive?: boolean;
}
export type LanguageSelector = string | LanguageFilter | Array<string | LanguageFilter>;
export type LanguageSelector = string | LanguageFilter | ReadonlyArray<string | LanguageFilter>;
export function score(selector: LanguageSelector | undefined, candidateUri: URI, candidateLanguage: string, candidateIsSynchronized: boolean): number {
......
......@@ -1943,18 +1943,18 @@ declare module 'vscode' {
/**
* A language id, like `typescript`.
*/
language?: string;
readonly language?: string;
/**
* A Uri [scheme](#Uri.scheme), like `file` or `untitled`.
*/
scheme?: string;
readonly scheme?: string;
/**
* A [glob pattern](#GlobPattern) that is matched on the absolute path of the document. Use a [relative pattern](#RelativePattern)
* to filter documents to a [workspace folder](#WorkspaceFolder).
*/
pattern?: GlobPattern;
readonly pattern?: GlobPattern;
}
/**
......@@ -1969,7 +1969,7 @@ declare module 'vscode' {
* @example
* let sel:DocumentSelector = { scheme: 'file', language: 'typescript' };
*/
export type DocumentSelector = DocumentFilter | string | Array<DocumentFilter | string>;
export type DocumentSelector = DocumentFilter | string | ReadonlyArray<DocumentFilter | string>;
/**
* A provider result represents the values a provider, like the [`HoverProvider`](#HoverProvider),
......
......@@ -992,7 +992,7 @@ declare module 'vscode' {
//#region @jrieken -> exclusive document filters
export interface DocumentFilter {
exclusive?: boolean;
readonly exclusive?: boolean;
}
//#endregion
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册