How to use the vscode-languageserver-protocol.TextDocument.create function in vscode-languageserver-protocol

To help you get started, we’ve selected a few vscode-languageserver-protocol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neoclide / coc.nvim / src / model / document.ts View on Github external
public async applyEdits(_nvim: Neovim, edits: TextEdit[], sync = true): Promise {
    if (edits.length == 0) return
    let orig = this.lines.join('\n') + (this.eol ? '\n' : '')
    let textDocument = TextDocument.create(this.uri, this.filetype, 1, orig)
    let content = TextDocument.applyEdits(textDocument, edits)
    // could be equal sometimes
    if (orig === content) {
      this.createDocument()
    } else {
      let d = diffLines(orig, content)
      await this.buffer.setLines(d.replacement, {
        start: d.start,
        end: d.end,
        strictIndexing: false
      })
      // can't wait vim sync buffer
      this.lines = (this.eol && content.endsWith('\n') ? content.slice(0, -1) : content).split('\n')
      if (sync) this.forceSync()
    }
  }
github neoclide / coc.nvim / src / snippets / snippet.ts View on Github external
private update(): void {
    const snippet = this.tmSnippet
    const placeholders = snippet.placeholders
    const { line, character } = this.position
    const document = TextDocument.create('untitled:/1', 'snippet', 0, snippet.toString())

    this._placeholders = placeholders.map((p, idx) => {
      const offset = snippet.offset(p)
      const position = document.positionAt(offset)
      const start: Position = {
        line: line + position.line,
        character: position.line == 0 ? character + position.character : position.character
      }
      const value = p.toString()
      const lines = value.split('\n')
      let res: CocSnippetPlaceholder = {
        range: Range.create(start, {
          line: start.line + lines.length - 1,
          character: lines.length == 1 ? start.character + value.length : lines[lines.length - 1].length
        }),
        transform: p.transform != null,
github neoclide / coc.nvim / src / snippets / snippet.ts View on Github external
public get range(): Range {
    let { position } = this
    const content = this.tmSnippet.toString()
    const doc = TextDocument.create('untitled:/1', 'snippet', 0, content)
    const pos = doc.positionAt(content.length)
    const end = pos.line == 0 ? position.character + pos.character : pos.character
    return Range.create(position, Position.create(position.line + pos.line, end))
  }
github neoclide / coc.nvim / src / model / document.ts View on Github external
private createDocument(changeCount = 1): void {
    let { version, uri, filetype } = this
    version = version + changeCount
    this.textDocument = TextDocument.create(
      uri,
      filetype,
      version,
      this.getDocumentContent()
    )
  }
github neoclide / coc.nvim / src / model / document.ts View on Github external
public setFiletype(filetype: string): void {
    let { uri, version } = this
    this._filetype = this.convertFiletype(filetype)
    version = version ? version + 1 : 1
    let textDocument = TextDocument.create(uri, this.filetype, version, this.content)
    this.textDocument = textDocument
  }
github neoclide / coc.nvim / src / model / configurations.ts View on Github external
export function convertErrors(uri: string, content: string, errors: ParseError[]): ErrorItem[] {
  let items: ErrorItem[] = []
  let document = TextDocument.create(uri, 'json', 0, content)
  for (let err of errors) {
    let msg = 'parse error'
    switch (err.error) {
      case 2:
        msg = 'invalid number'
        break
      case 8:
        msg = 'close brace expected'
        break
      case 5:
        msg = 'colon expeted'
        break
      case 6:
        msg = 'comma expected'
        break
      case 9: