feat: Command、TextLine、TextDocument

youngjuning-patch-1
youngjuning 2 years ago
parent 8374d258e1
commit 5f7ad41ec5

@ -8,10 +8,6 @@ API 列表使用 Typedoc 从 [vscode.d.ts](https://github.com/youngjuning/vscode
## 贡献指南 ## 贡献指南
- [专业术语](https://github.com/vscode-cn/vscode-api-cn/issues/27)
### 成为译者
*vscode.d.ts* 文件的注释进行翻译,然后提交 PR 即可。 *vscode.d.ts* 文件的注释进行翻译,然后提交 PR 即可。
### 本地预览 ### 本地预览

331
vscode.d.ts vendored

@ -1,6 +1,6 @@
/*--------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENCE in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
declare module vscode { declare module vscode {
@ -9,185 +9,162 @@ declare module vscode {
*/ */
export const version: string; export const version: string;
/** /**
* UI * UI
* *
*
* Represents a reference to a command. Provides a title which
* will be used to represent a command in the UI and, optionally,
* an array of arguments which will be passed to the command handler
* function when invoked.
* *
* @maintainer {@link https://github.com/youngjuning @youngjuning} * @maintainer {@link https://youngjuning.js.org @youngjuning}
*/ */
export interface Command { export interface Command {
/** /**
* `save` * `save`
* */
* Title of the command, like `save`.
*/
title: string; title: string;
/** /**
* *
* * @see {@link commands.registerCommand}
* The identifier of the actual command handler. */
*
* @see {@link commands.registerCommand}
*/
command: string; command: string;
/** /**
* UI * UI
*
* A tooltip for the command, when represented in the UI.
*/ */
tooltip?: string; tooltip?: string;
/** /**
* *
*
* Arguments that the command handler should be
* invoked with.
*/ */
arguments?: any[]; arguments?: any[];
} }
/** /**
* Represents a line of text, such as a line of source code. *
* *
* TextLine objects are __immutable__. When a {@link TextDocument document} changes, * TextLine __immutable__ {@link TextDocument document}
* previously retrieved lines will not represent the latest state. *
*/ *
* @maintainer {@link https://youngjuning.js.org @youngjuning}
*/
export interface TextLine { export interface TextLine {
/** /**
* The zero-based line number. * 0
*/ */
readonly lineNumber: number; readonly lineNumber: number;
/** /**
* The text of this line without the line separator characters. *
*/ */
readonly text: string; readonly text: string;
/** /**
* The range this line covers without the line separator characters. *
*/ */
readonly range: Range; readonly range: Range;
/** /**
* The range this line covers with the line separator characters. *
*/ */
readonly rangeIncludingLineBreak: Range; readonly rangeIncludingLineBreak: Range;
/** /**
* The offset of the first character which is not a whitespace character as defined * `/\s/`
* by `/\s/`. **Note** that if a line is all whitespace the length of the line is returned. */
*/
readonly firstNonWhitespaceCharacterIndex: number; readonly firstNonWhitespaceCharacterIndex: number;
/** /**
* Whether this line is whitespace only, shorthand * `/\s/`
* for {@link TextLine.firstNonWhitespaceCharacterIndex} === {@link TextLine.text TextLine.text.length}. * {@link TextLine.firstNonWhitespaceCharacterIndex} === {@link TextLine.text TextLine.text.length}
*/ */
readonly isEmptyOrWhitespace: boolean; readonly isEmptyOrWhitespace: boolean;
} }
/** /**
* Represents a text document, such as a source file. Text documents have * {@link TextLine lines}
* {@link TextLine lines} and knowledge about an underlying resource like a file. *
*/ * @maintainer {@link https://youngjuning.js.org @youngjuning}
*/
export interface TextDocument { export interface TextDocument {
/** /**
* The associated uri for this document. * uri
* *
* *Note* that most documents use the `file`-scheme, which means they are files on disk. However, **not** all documents are * ** 使 `file`-scheme****
* saved on disk and therefore the `scheme` must be checked before trying to access the underlying file or siblings on disk. * 访 `scheme`
* *
* @see {@link FileSystemProvider} * @see {@link FileSystemProvider}
* @see {@link TextDocumentContentProvider} * @see {@link TextDocumentContentProvider}
*/ */
readonly uri: Uri; readonly uri: Uri;
/** /**
* The file system path of the associated resource. Shorthand * {@link TextDocument.uri TextDocument.uri.fsPath}
* notation for {@link TextDocument.uri TextDocument.uri.fsPath}. Independent of the uri scheme. * uri scheme
*/ */
readonly fileName: string; readonly fileName: string;
/** /**
* Is this document representing an untitled file which has never been saved yet. *Note* that * **
* this does not mean the document will be saved to disk, use {@linkcode Uri.scheme} * 使 {@linkcode Uri.scheme} {@link FileSystemProvider saved} `file``ftp`
* to figure out where a document will be {@link FileSystemProvider saved}, e.g. `file`, `ftp` etc. */
*/
readonly isUntitled: boolean; readonly isUntitled: boolean;
/** /**
* The identifier of the language associated with this document. *
*/ */
readonly languageId: string; readonly languageId: string;
/** /**
* The version number of this document (it will strictly increase after each * /
* change, including undo/redo). */
*/
readonly version: number; readonly version: number;
/** /**
* `true` if there are unpersisted changes. * `true`
*/ */
readonly isDirty: boolean; readonly isDirty: boolean;
/** /**
* `true` if the document has been closed. A closed document isn't synchronized anymore * `true`
* and won't be re-used when the same resource is opened again. */
*/
readonly isClosed: boolean; readonly isClosed: boolean;
/** /**
* Save the underlying file. *
* *
* @return A promise that will resolve to true when the file * @return promise resolve `true` `false`
* has been saved. If the file was not dirty or the save failed, */
* will return false.
*/
save(): Thenable<boolean>; save(): Thenable<boolean>;
/** /**
* The {@link EndOfLine end of line} sequence that is predominately * 使 {@link EndOfLine end of line}
* used in this document. */
*/
readonly eol: EndOfLine; readonly eol: EndOfLine;
/** /**
* The number of lines in this document. *
*/ */
readonly lineCount: number; readonly lineCount: number;
/** /**
* Returns a text line denoted by the line number. Note * **
* that the returned object is *not* live and changes to the *
* document are not reflected. * @param line [0, lineCount)
* * @return {@link TextLine line}
* @param line A line number in [0, lineCount). */
* @return A {@link TextLine line}.
*/
lineAt(line: number): TextLine; lineAt(line: number): TextLine;
/** /**
* Returns a text line denoted by the position. Note * **
* that the returned object is *not* live and changes to the *
* document are not reflected. * {@link TextDocument.validatePosition adjusted}
* *
* The position will be {@link TextDocument.validatePosition adjusted}. * @see {@link TextDocument.lineAt}
* *
* @see {@link TextDocument.lineAt} * @param position
* * @return {@link TextLine line}
* @param position A position. */
* @return A {@link TextLine line}.
*/
lineAt(position: Position): TextLine; lineAt(position: Position): TextLine;
/** /**
@ -198,70 +175,69 @@ declare module vscode {
* @param position A position. * @param position A position.
* @return A valid zero-based offset. * @return A valid zero-based offset.
*/ */
/**
* 0
*
* {@link TextDocument.validatePosition adjusted}
*
* @param position
* @return 0
*/
offsetAt(position: Position): number; offsetAt(position: Position): number;
/** /**
* Converts a zero-based offset to a position. * 0
* *
* @param offset A zero-based offset. * @param offset 0
* @return A valid {@link Position}. * @return {@link Position}
*/ */
positionAt(offset: number): Position; positionAt(offset: number): Position;
/** /**
* Get the text of this document. A substring can be retrieved by providing * {@link TextDocument.validateRange adjusted}
* a range. The range will be {@link TextDocument.validateRange adjusted}. */
*
* @param range Include only the text included by the range.
* @return The text inside the provided range or the entire text.
*/
getText(range?: Range): string; getText(range?: Range): string;
/** /**
* Get a word-range at the given position. By default words are defined by * -_
* common separators, like space, -, _, etc. In addition, per language custom * []
* [word definitions} can be defined. It *
* is also possible to provide a custom regular expression. * * * 1:*
* *
* * *Note 1:* A custom regular expression must not match the empty string and * * * 2:* 使 {@linkcode TextLine.text}
* if it does, it will be ignored. *
* * *Note 2:* A custom regular expression will fail to match multiline strings * {@link TextDocument.validatePosition adjusted}
* and in the name of speed regular expressions should not match words with *
* spaces. Use {@linkcode TextLine.text} for more complex, non-wordy, scenarios. * @param position
* * @param regex
* The position will be {@link TextDocument.validatePosition adjusted}. * @return `undefined`
* */
* @param position A position.
* @param regex Optional regular expression that describes what a word is.
* @return A range spanning a word, or `undefined`.
*/
getWordRangeAtPosition(position: Position, regex?: RegExp): Range | undefined; getWordRangeAtPosition(position: Position, regex?: RegExp): Range | undefined;
/** /**
* Ensure a range is completely contained in this document. *
* *
* @param range A range. * @param range
* @return The given range or a new, adjusted range. * @return
*/ */
validateRange(range: Range): Range; validateRange(range: Range): Range;
/** /**
* Ensure a position is contained in the range of this document. *
* *
* @param position A position. * @param position
* @return The given position or a new, adjusted position. * @return
*/ */
validatePosition(position: Position): Position; validatePosition(position: Position): Position;
} }
/** /**
* Represents a line and character position, such as *
* the position of the cursor. *
* * Position 使 {@link Position.with with} {@link Position.translate translate}
* Position objects are __immutable__. Use the {@link Position.with with} or *
* {@link Position.translate translate} methods to derive new positions * @maintainer {@link https://youngjuning.js.org @youngjuning}
* from an existing position. */
*/
export class Position { export class Position {
/** /**
@ -381,6 +357,11 @@ declare module vscode {
* {@link Range.intersection intersection}, or {@link Range.union union} methods * {@link Range.intersection intersection}, or {@link Range.union union} methods
* to derive new ranges from an existing range. * to derive new ranges from an existing range.
*/ */
/**
*
*
* 使 {@link Range.with with} {@link Range.intersection intersection}{@link Range.union union}
*/
export class Range { export class Range {
/** /**

Loading…
Cancel
Save