How to use the vscode-languageserver-protocol.CodeActionKind.QuickFix 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 sourcegraph / sourcegraph-typescript / src / extension / extension.ts View on Github external
connection.onNotification(PublishDiagnosticsNotification.type, async params => {
                const uri = new URL(params.uri)
                const sourcegraphTextDocumentUri = toSourcegraphTextDocumentUri(uri)
                diagnosticsByUri.set(sourcegraphTextDocumentUri.href, params.diagnostics)
                // Mark quick fixes with a light bulb
                const codeActionDecorations: sourcegraph.TextDocumentDecoration[] = []
                for (const diagnostic of params.diagnostics) {
                    const codeActionParams: CodeActionParams = {
                        textDocument: {
                            uri: uri.href,
                        },
                        range: diagnostic.range,
                        context: {
                            diagnostics: [diagnostic],
                            only: [CodeActionKind.QuickFix],
                        },
                    }
                    try {
                        const codeActions = await connection.sendRequest(CodeActionRequest.type, codeActionParams)
                        codeActionDecorations.push(
                            ...asArray(codeActions).map(
                                (codeAction): sourcegraph.TextDocumentDecoration => ({
                                    range: convertRange(diagnostic.range),
                                    after: {
                                        contentText: '💡',
                                        hoverMessage: codeAction.title,
                                    },
                                })
                            )
                        )
                    } catch (err) {
github neoclide / coc-tsserver / src / server / features / quickfix.ts View on Github external
tsAction: Proto.CodeFixAction
  ): Promise {
    if (!tsAction.fixId || !this.client.apiVersion.gte(API.v270)) {
      return undefined
    }

    // Make sure there are multiple diagnostics of the same type in the file
    if (!this.client.diagnosticsManager
      .getDiagnostics(document.uri)
      .some(x => x.code === diagnostic.code && x !== diagnostic)) {
      return
    }

    const action: CodeAction = {
      title: tsAction.fixAllDescription || 'Fix all in file',
      kind: CodeActionKind.QuickFix
    }
    action.diagnostics = [diagnostic]
    action.command = {
      command: ApplyFixAllCodeAction.ID,
      arguments: [file, tsAction],
      title: ''
    }
    return action
  }
}
github neoclide / coc.nvim / src / extensions / tsserver / features / quickfix.ts View on Github external
tsAction: Proto.CodeFixAction
  ): Promise {
    if (!tsAction.fixId || !this.client.apiVersion.gte(API.v270)) {
      return undefined
    }

    // Make sure there are multiple diagnostics of the same type in the file
    if (!this.diagnosticsManager
      .getDiagnostics(document.uri)
      .some(x => x.code === diagnostic.code && x !== diagnostic)) {
      return
    }

    const action: CodeAction = {
      title: tsAction.fixAllDescription || 'Fix all in file',
      kind: CodeActionKind.QuickFix
    }
    action.diagnostics = [diagnostic]
    action.command = {
      command: ApplyFixAllCodeAction.ID,
      arguments: [file, tsAction],
      title: ''
    }
    return action
  }
}
github neoclide / coc.nvim / src / extensions / tsserver / features / quickfix.ts View on Github external
private getSingleFixForTsCodeAction(
    diagnostic: Diagnostic,
    tsAction: Proto.CodeAction
  ): CodeAction {
    const codeAction: CodeAction = {
      title: tsAction.description,
      kind: CodeActionKind.QuickFix
    }
    codeAction.edit = getEditForCodeAction(this.client, tsAction)
    codeAction.diagnostics = [diagnostic]
    if (tsAction.commands) {
      codeAction.command = {
        command: ApplyCodeActionCommand.ID,
        arguments: [tsAction],
        title: tsAction.description
      }
    }
    return codeAction
  }
github neoclide / coc-tsserver / src / server / languageProvider.ts View on Github external
'tsserver')
    )

    this.disposables.push(
      languages.registerCodeActionProvider(
        languageIds,
        new QuickfixProvider(client),
        'tsserver',
        [CodeActionKind.QuickFix]))

    this.disposables.push(
      languages.registerCodeActionProvider(
        languageIds,
        new ImportfixProvider(this.client.bufferSyncSupport),
        'tsserver',
        [CodeActionKind.QuickFix]))
    let cachedResponse = new CachedNavTreeResponse()
    if (this.client.apiVersion.gte(API.v206)
      && conf.get('referencesCodeLens.enable')) {
      this.disposables.push(
        languages.registerCodeLensProvider(
          languageIds,
          new ReferencesCodeLensProvider(client, cachedResponse)))
    }

    if (this.client.apiVersion.gte(API.v220)
      && conf.get('implementationsCodeLens.enable')) {
      this.disposables.push(
        languages.registerCodeLensProvider(
          languageIds,
          new ImplementationsCodeLensProvider(client, cachedResponse)))
    }
github neoclide / coc.nvim / src / handler / index.ts View on Github external
public async getQuickfixActions(range?: Range): Promise {
    let document = await workspace.document
    if (!document) return []
    range = range || Range.create(0, 0, document.lineCount, 0)
    let diagnostics = diagnosticManager.getDiagnosticsInRange(document.textDocument, range)
    let context: CodeActionContext = { diagnostics, only: [CodeActionKind.QuickFix] }
    let codeActionsMap = await languages.getCodeActions(document.textDocument, range, context, true)
    if (!codeActionsMap) return []
    let codeActions: CodeAction[] = []
    for (let clientId of codeActionsMap.keys()) {
      let actions = codeActionsMap.get(clientId)
      for (let action of actions) {
        if (action.kind !== CodeActionKind.QuickFix) continue
        (action as any).clientId = clientId
        codeActions.push(action)
      }
    }
    return codeActions
  }
github neoclide / coc.nvim / src / handler / index.ts View on Github external
public async getQuickfixActions(range?: Range): Promise {
    let document = await workspace.document
    if (!document) return []
    range = range || Range.create(0, 0, document.lineCount, 0)
    let diagnostics = diagnosticManager.getDiagnosticsInRange(document.textDocument, range)
    let context: CodeActionContext = { diagnostics, only: [CodeActionKind.QuickFix] }
    let codeActionsMap = await languages.getCodeActions(document.textDocument, range, context, true)
    if (!codeActionsMap) return []
    let codeActions: CodeAction[] = []
    for (let clientId of codeActionsMap.keys()) {
      let actions = codeActionsMap.get(clientId)
      for (let action of actions) {
        if (action.kind !== CodeActionKind.QuickFix) continue
        (action as any).clientId = clientId
        codeActions.push(action)
      }
    }
    return codeActions
  }
github neoclide / coc.nvim / src / handler / index.ts View on Github external
public async doQuickfix(): Promise {
    let actions = await this.getCurrentCodeActions(null, [CodeActionKind.QuickFix])
    if (!actions || actions.length == 0) {
      workspace.showMessage('No quickfix action available', 'warning')
      return false
    }
    await this.applyCodeAction(actions[0])
    await this.nvim.command(`silent! call repeat#set("\\(coc-fix-current)", -1)`)
    return true
  }