Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "vscode-languageserver-protocol in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'vscode-languageserver-protocol' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

let pos: Position = insertLeave ? { line: position.line + 1, character: 0 } : position
    try {
      let edits = await languages.provideDocumentOntTypeEdits(ch, doc.textDocument, pos)
      // changed by other process
      if (doc.changedtick != changedtick) return
      if (insertLeave) {
        edits = edits.filter(edit => {
          return edit.range.start.line < position.line + 1
        })
      }
      if (edits && edits.length) {
        await doc.applyEdits(this.nvim, edits)
        let newLine = doc.getline(position.line)
        if (newLine.length > origLine.length) {
          let character = position.character + (newLine.length - origLine.length)
          await workspace.moveTo(Position.create(position.line, character))
        }
      }
    } catch (e) {
      if (!/timeout\s/.test(e.message)) {
        console.error(`Error on formatOnType: ${e.message}`) // tslint:disable-line
      }
    }
  }
let { id } = service
    if (!id) logger.error('invalid service configuration. ', service.name)
    if (this.registered.get(id)) return
    this.registered.set(id, service)
    logger.info(`registered service "${id}"`)
    if (this.shouldStart(service)) {
      service.start() // tslint:disable-line
    }
    if (service.state == ServiceStat.Running) {
      this.emit('ready', id)
    }
    service.onServiceReady(() => {
      logger.info(`service ${id} started`)
      this.emit('ready', id)
    }, null, this.disposables)
    return Disposable.create(() => {
      service.stop()
      service.dispose()
      this.registered.delete(id)
    })
  }
private async applyTextEdit(item: CompletionItem, option: CompleteOption): Promise {
    let { nvim } = this
    let { textEdit } = item
    if (!textEdit) return false
    let { line, bufnr, linenr } = option
    let doc = workspace.getDocument(bufnr)
    if (!doc) return false
    let { range, newText } = textEdit
    let isSnippet = item.insertTextFormat === InsertTextFormat.Snippet
    // replace inserted word
    let start = line.substr(0, range.start.character)
    let end = line.substr(range.end.character)
    if (isSnippet) {
      await doc.applyEdits(nvim, [{
        range: Range.create(linenr - 1, 0, linenr, 0),
        newText: `${start}${end}\n`
      }])
      // can't select, since additionalTextEdits would break selection
      let pos = Position.create(linenr - 1, range.start.character)
      return await snippetManager.insertSnippet(newText, false, Range.create(pos, pos))
    }
    let newLines = `${start}${newText}${end}`.split('\n')
    if (newLines.length == 1) {
      await nvim.call('coc#util#setline', [linenr, newLines[0]])
      await workspace.moveTo(Position.create(linenr - 1, (start + newText).length))
    } else {
      let buffer = nvim.createBuffer(bufnr)
      await buffer.setLines(newLines, {
        start: linenr - 1,
        end: linenr,
        strictIndexing: false
if (!textEdit) return false
    let { line, bufnr, linenr } = option
    let doc = workspace.getDocument(bufnr)
    if (!doc) return false
    let { range, newText } = textEdit
    let isSnippet = item.insertTextFormat === InsertTextFormat.Snippet
    // replace inserted word
    let start = line.substr(0, range.start.character)
    let end = line.substr(range.end.character)
    if (isSnippet) {
      await doc.applyEdits(nvim, [{
        range: Range.create(linenr - 1, 0, linenr, 0),
        newText: `${start}${end}\n`
      }])
      // can't select, since additionalTextEdits would break selection
      let pos = Position.create(linenr - 1, range.start.character)
      return await snippetManager.insertSnippet(newText, false, Range.create(pos, pos))
    }
    let newLines = `${start}${newText}${end}`.split('\n')
    if (newLines.length == 1) {
      await nvim.call('coc#util#setline', [linenr, newLines[0]])
      await workspace.moveTo(Position.create(linenr - 1, (start + newText).length))
    } else {
      let buffer = nvim.createBuffer(bufnr)
      await buffer.setLines(newLines, {
        start: linenr - 1,
        end: linenr,
        strictIndexing: false
      })
      let line = linenr - 1 + newLines.length - 1
      let character = newLines[newLines.length - 1].length - end.length
      await workspace.moveTo({ line, character })
// replace inserted word
    let start = line.substr(0, range.start.character)
    let end = line.substr(range.end.character)
    if (isSnippet) {
      await doc.applyEdits(nvim, [{
        range: Range.create(linenr - 1, 0, linenr, 0),
        newText: `${start}${end}\n`
      }])
      // can't select, since additionalTextEdits would break selection
      let pos = Position.create(linenr - 1, range.start.character)
      return await snippetManager.insertSnippet(newText, false, Range.create(pos, pos))
    }
    let newLines = `${start}${newText}${end}`.split('\n')
    if (newLines.length == 1) {
      await nvim.call('coc#util#setline', [linenr, newLines[0]])
      await workspace.moveTo(Position.create(linenr - 1, (start + newText).length))
    } else {
      let buffer = nvim.createBuffer(bufnr)
      await buffer.setLines(newLines, {
        start: linenr - 1,
        end: linenr,
        strictIndexing: false
      })
      let line = linenr - 1 + newLines.length - 1
      let character = newLines[newLines.length - 1].length - end.length
      await workspace.moveTo({ line, character })
    }
    return false
  }
public async showSignatureHelp(): Promise {
    if (this.signatureTokenSource) {
      this.signatureTokenSource.cancel()
      this.signatureTokenSource.dispose()
      this.signatureTokenSource = null
    }
    let document = workspace.getDocument(workspace.bufnr)
    if (!document) return
    let position = await workspace.getCursorPosition()
    let part = document.getline(position.line).slice(0, position.character)
    if (/\)\s*$/.test(part)) return
    let idx = Math.max(part.lastIndexOf(','), part.lastIndexOf('('))
    if (idx != -1) position.character = idx + 1
    let tokenSource = this.signatureTokenSource = new CancellationTokenSource()
    let token = tokenSource.token
    let timer = setTimeout(() => {
      if (!token.isCancellationRequested) {
        tokenSource.cancel()
      }
    }, 3000)
    let signatureHelp = await languages.getSignatureHelp(document.textDocument, position, token)
    clearTimeout(timer)
    if (token.isCancellationRequested || !signatureHelp || signatureHelp.signatures.length == 0) {
      this.signatureFactory.close()
      return
    }
    let { activeParameter, activeSignature, signatures } = signatureHelp
    if (activeSignature) {
      // make active first
      let [active] = signatures.splice(activeSignature, 1)
public async onPumChange(ev: PopupChangeEvent): Promise {
    if (!this.activated) return
    if (this.document && this.document.uri.endsWith('%5BCommand%20Line%5D')) return
    this.cancel()
    let { completed_item, col, row, height, width, scrollbar } = ev
    let bounding: PumBounding = { col, row, height, width, scrollbar }
    this.currItem = completed_item.hasOwnProperty('word') ? completed_item : null
    // it's pum change by vim, ignore it
    if (this.lastInsert) return
    let resolvedItem = this.getCompleteItem(completed_item)
    if (!resolvedItem) {
      this.floating.close()
      return
    }
    let source = this.resolveTokenSource = new CancellationTokenSource()
    let { token } = source
    await sources.doCompleteResolve(resolvedItem, token)
    if (token.isCancellationRequested) return
    let docs = resolvedItem.documentation
    if (!docs && resolvedItem.info) {
      let { info } = resolvedItem
      let isText = /^[\w-\s.,\t]+$/.test(info)
      docs = [{ filetype: isText ? 'txt' : this.document.filetype, content: info }]
    }
    if (!docs || docs.length == 0) {
      this.floating.close()
    } else {
      if (token.isCancellationRequested) return
      await this.floating.show(docs, bounding, token)
    }
    this.resolveTokenSource = null
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()
    }
  }
fixId: tsAction.fixId
    }

    try {
      const res = await this.client.execute('getCombinedCodeFix', args, CancellationToken.None)
      if (res.type != 'response') {
        return
      }
      let { body } = res

      const edit = typeConverters.WorkspaceEdit.fromFileCodeEdits(
        this.client,
        body.changes
      )
      await workspace.applyEdit(edit)
      const token = CancellationToken.None

      const { commands } = body
      if (commands && commands.length) {
        for (const command of commands) {
          await this.client.execute('applyCodeActionCommand', { command }, token)
        }
      }
    } catch {
      // noop
    }
  }
}
}
            lines.push(...content.trim().split('\n'))
            docs.push({ filetype: item.language, content: item.value })
          }
        }
      } else if (typeof contents == 'string') {
        lines.push(...contents.split('\n'))
        docs.push({ content: contents, filetype: 'markdown' })
      } else if (MarkedString.is(contents)) { // tslint:disable-line
        let content = contents.value.trim()
        if (target == 'preview') {
          content = '``` ' + contents.language + '\n' + content + '\n```'
        }
        lines.push(...content.split('\n'))
        docs.push({ filetype: contents.language, content: contents.value })
      } else if (MarkupContent.is(contents)) {
        lines.push(...contents.value.split('\n'))
        docs.push({ filetype: contents.kind == 'markdown' ? 'markdown' : 'txt', content: contents.value })
      }
      i++
    }
    if (target == 'echo') {
      const msg = lines.join('\n').trim()
      if (msg.length) {
        await this.nvim.call('coc#util#echo_hover', msg)
      }
    } else if (target == 'float') {
      diagnosticManager.hideFloat()
      await this.hoverFactory.create(docs)
    } else {
      this.documentLines = lines
      let arr = await this.nvim.call('getcurpos') as number[]

Is your System Free of Underlying Vulnerabilities?
Find Out Now