vscode-languageserver-textdocument

  • Version 1.0.12
  • Published
  • 40.3 kB
  • No dependencies
  • MIT license

Install

npm i vscode-languageserver-textdocument
yarn add vscode-languageserver-textdocument
pnpm add vscode-languageserver-textdocument

Overview

A simple text document implementation for Node LSP servers

Index

Interfaces

interface Position

interface Position {}
  • Position in a text document expressed as zero-based line and character offset. The offsets are based on a UTF-16 string representation. So a string of the form a𐐀b the character offset of the character a is 0, the character offset of 𐐀 is 1 and the character offset of b is 3 since 𐐀 is represented using two code units in UTF-16.

    Positions are line end character agnostic. So you can not specify a position that denotes \r|\n or \n| where | represents the character offset.

property character

character: number;
  • Character offset on a line in a document (zero-based).

    The meaning of this offset is determined by the negotiated PositionEncodingKind.

    If the character value is greater than the line length it defaults back to the line length. This property is implementation specific.

property line

line: number;
  • Line position in a document (zero-based).

    If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document. If a line number is negative, it defaults to 0.

    The above two properties are implementation specific.

interface Range

interface Range {}
  • A range in a text document expressed as (zero-based) start and end positions.

    If you want to specify a range that contains a line including the line ending character(s) then use an end position denoting the start of the next line. For example:

    {
    start: { line: 5, character: 23 }
    end : { line 6, character : 0 }
    }

property end

end: Position;
  • The range's end position.

property start

start: Position;
  • The range's start position.

interface TextDocument

interface TextDocument {}
  • A simple text document. Not to be implemented. The document keeps the content as string.

property languageId

readonly languageId: string;
  • The identifier of the language associated with this document.

    Modifiers

    • @readonly

property lineCount

readonly lineCount: number;
  • The number of lines in this document.

    Modifiers

    • @readonly

property uri

readonly uri: DocumentUri;
  • The associated URI for this document. Most documents have the __file__-scheme, indicating that they represent files on disk. However, some documents may have other schemes indicating that they are not available on disk.

    Modifiers

    • @readonly

property version

readonly version: number;
  • The version number of this document (it will increase after each change, including undo/redo).

    Modifiers

    • @readonly

method getText

getText: (range?: Range) => string;
  • Get the text of this document. A substring can be retrieved by providing a range.

    Parameter range

    (optional) An range within the document to return. If no range is passed, the full content is returned. Invalid range positions are adjusted as described in Position.line and Position.character. If the start range position is greater than the end range position, then the effect of getText is as if the two positions were swapped.

    The text of this document or a substring of the text if a range is provided.

method offsetAt

offsetAt: (position: Position) => number;
  • Converts the position to a zero-based offset. Invalid positions are adjusted as described in Position.line and Position.character.

    Parameter position

    A position. A valid zero-based offset.

method positionAt

positionAt: (offset: number) => Position;
  • Converts a zero-based offset to a position.

    Parameter offset

    A zero-based offset. A valid .

    Example 1

    The text document "ab\ncd" produces: * position { line: 0, character: 0 } for offset 0. * position { line: 0, character: 1 } for offset 1. * position { line: 0, character: 2 } for offset 2. * position { line: 1, character: 0 } for offset 3. * position { line: 1, character: 1 } for offset 4.

interface TextEdit

interface TextEdit {}
  • A text edit applicable to a text document.

property newText

newText: string;
  • The string to be inserted. For delete operations use an empty string.

property range

range: Range;
  • The range of the text document to be manipulated. To insert text into a document create a range where start === end.

Type Aliases

type DocumentUri

type DocumentUri = string;
  • A tagging type for string properties that are actually URIs.

type TextDocumentContentChangeEvent

type TextDocumentContentChangeEvent =
| {
/**
* The range of the document that changed.
*/
range: Range;
/**
* The optional length of the range that got replaced.
*
* @deprecated use range instead.
*/
rangeLength?: number;
/**
* The new text for the provided range.
*/
text: string;
}
| {
/**
* The new text of the whole document.
*/
text: string;
};
  • An event describing a change to a text document. If range and rangeLength are omitted the new text is considered to be the full content of the document.

Namespaces

namespace TextDocument

namespace TextDocument {}

    function applyEdits

    applyEdits: (document: TextDocument, edits: TextEdit[]) => string;

      function create

      create: (
      uri: DocumentUri,
      languageId: string,
      version: number,
      content: string
      ) => TextDocument;
      • Creates a new text document.

        Parameter uri

        The document's uri.

        Parameter languageId

        The document's language Id.

        Parameter version

        The document's initial version number.

        Parameter content

        The document's content.

      function update

      update: (
      document: TextDocument,
      changes: TextDocumentContentChangeEvent[],
      version: number
      ) => TextDocument;
      • Updates a TextDocument by modifying its content.

        Parameter document

        the document to update. Only documents created by TextDocument.create are valid inputs.

        Parameter changes

        the changes to apply to the document.

        Parameter version

        the changes version for the document.

        Returns

        The updated TextDocument. Note: That's the same document instance passed in as first parameter.

      Package Files (1)

      Dependencies (0)

      No dependencies.

      Dev Dependencies (0)

      No dev dependencies.

      Peer Dependencies (0)

      No peer dependencies.

      Badge

      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/vscode-languageserver-textdocument.

      • Markdown
        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/vscode-languageserver-textdocument)
      • HTML
        <a href="https://www.jsdocs.io/package/vscode-languageserver-textdocument"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>