How to use the vscode-languageserver-protocol.CancellationToken.None 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-tsserver / src / server / features / quickfix.ts View on Github external
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
    }
  }
}
github neoclide / coc-tsserver / src / server / utils / codeAction.ts View on Github external
export async function applyCodeActionCommands(
  client: ITypeScriptServiceClient,
  action: Proto.CodeAction
): Promise {
  // make sure there is command
  if (action.commands && action.commands.length) {
    for (const command of action.commands) {
      const response = await client.execute('applyCodeActionCommand', { command }, CancellationToken.None)
      if (!response || response.type != 'response' || !response.body) {
        return false
      }
    }
  }
  return true
}
github neoclide / coc.nvim / src / extensions / tsserver / commands.ts View on Github external
async function goToProjectConfig(clientHost: TypeScriptServiceClientHost, uri: string): Promise {
  if (!clientHost.handles(uri)) {
    workspace.showMessage('Could not determine TypeScript or JavaScript project. Unsupported file type', 'warning')
    return
  }
  const client = clientHost.serviceClient
  const file = client.toPath(uri)
  let res: ProjectInfoResponse | undefined
  try {
    res = await client.execute('projectInfo', { file, needFileNameList: false }, CancellationToken.None)
  } catch {
    // noop
  }
  if (!res || !res.body) {
    workspace.showMessage('Could not determine TypeScript or JavaScript project.', 'warning')
    return
  }

  const { configFileName } = res.body
  if (configFileName && !isImplicitProjectConfigFile(configFileName)) {
    await workspace.openResource(URI.file(configFileName).toString())
    return
  }

  workspace.showMessage('Config file not found', 'warning')
}
github neoclide / coc-tsserver / src / server / commands.ts View on Github external
async function goToProjectConfig(clientHost: TypeScriptServiceClientHost, uri: string): Promise {
  if (!clientHost.handles(uri)) {
    workspace.showMessage('Could not determine TypeScript or JavaScript project. Unsupported file type', 'warning')
    return
  }
  const client = clientHost.serviceClient
  const file = client.toPath(uri)
  let res
  try {
    res = await client.execute('projectInfo', { file, needFileNameList: false }, CancellationToken.None)
  } catch {
    // noop
  }
  if (!res || !res.body) {
    workspace.showMessage('Could not determine TypeScript or JavaScript project.', 'warning')
    return
  }

  const { configFileName } = res.body
  if (configFileName && !isImplicitProjectConfigFile(configFileName)) {
    await workspace.openResource(URI.file(configFileName).toString())
    return
  }

  workspace.showMessage('Config file not found', 'warning')
}
github neoclide / coc-tsserver / src / server / features / quickfix.ts View on Github external
tsAction: Proto.CodeFixAction
  ): Promise {
    if (!tsAction.fixId) {
      return
    }

    const args: Proto.GetCombinedCodeFixRequestArgs = {
      scope: {
        type: 'file',
        args: { file }
      },
      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)
github neoclide / coc-tsserver / src / server / features / refactor.ts View on Github external
public async execute(
    document: TextDocument,
    file: string,
    refactor: string,
    action: string,
    range: Range
  ): Promise {
    const args: Proto.GetEditsForRefactorRequestArgs = {
      ...typeConverters.Range.toFileRangeRequestArgs(file, range),
      refactor,
      action
    }
    const response = await this.client.execute('getEditsForRefactor', args, CancellationToken.None) as any
    const body = response && response.body
    if (!body || !body.edits.length) {
      return false
    }

    const workspaceEdit = await this.toWorkspaceEdit(body)
    if (!(await workspace.applyEdit(workspaceEdit))) {
      return false
    }
    const renameLocation = body.renameLocation
    if (renameLocation) {
      commands.executeCommand('editor.action.rename',
        document.uri,
        typeConverters.Position.fromLocation(renameLocation)
      )
    }
github neoclide / coc-tsserver / src / server / organizeImports.ts View on Github external
    const response = await this.client.interruptGetErr(() => this.client.execute('organizeImports', args, CancellationToken.None))
    if (!response || response.type != 'response' || !response.success) {
github neoclide / coc-tsserver / src / server / features / updatePathOnRename.ts View on Github external
const response = await this.client.interruptGetErr(() => {
      const args: Proto.GetEditsForFileRenameRequestArgs = {
        oldFilePath: oldFile,
        newFilePath: newFile,
      }
      return this.client.execute('getEditsForFileRename', args, CancellationToken.None)
    })
    if (!response || response.type != 'response' || !response.body) {
github sourcegraph / sourcegraph-typescript / src / server / server.ts View on Github external
async function ensureDependenciesForDocument(
        textDocumentUri: URL,
        { tracer, span, token = CancellationToken.None }: { tracer: Tracer; span?: Span; token?: CancellationToken }
    ): Promise {
        await tracePromise('Ensure dependencies', tracer, span, async span => {
            throwIfCancelled(token)
            const parentPackageRoots = findParentPackageRoots(textDocumentUri)
            span.setTag('packageJsonLocations', parentPackageRoots.map(String))
            logger.log(`Ensuring dependencies for text document ${textDocumentUri} defined in`, [
                ...parentPackageRoots.map(String),
            ])
            await Promise.all(
                parentPackageRoots.map(async packageRoot => {
                    await ensureDependenciesForPackageRoot(packageRoot, { tracer, span, token })
                })
            )
        })
    }
github neoclide / coc-tsserver / src / server / features / quickfix.ts View on Github external
return new Promise>((resolve, reject) => {
        this.client.execute('getSupportedCodeFixes', null, CancellationToken.None).then(res => {
          if (res.type !== 'response') {
            resolve(new Set())
            return
          }
          let codes = res.body.map(code => +code).filter(code => !isNaN(code))
          resolve(new Set(codes))
        }, reject)
      })
    }