How to use the vscode-languageserver-protocol.CodeActionKind.Refactor 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 / extensions / tsserver / features / refactor.ts View on Github external
private static getKind(refactor: Proto.RefactorActionInfo): string {
    if (refactor.name.startsWith('function_')) {
      return TypeScriptRefactorProvider.extractFunctionKind
    } else if (refactor.name.startsWith('constant_')) {
      return TypeScriptRefactorProvider.extractConstantKind
    } else if (refactor.name.startsWith('Move')) {
      return TypeScriptRefactorProvider.moveKind
    }
    return CodeActionKind.Refactor
  }
}
github neoclide / coc.nvim / src / extensions / tsserver / features / refactor.ts View on Github external
private convertApplicableRefactors(
    body: Proto.ApplicableRefactorInfo[],
    document: TextDocument,
    file: string,
    rangeOrSelection: Range
  ): CodeAction[] {
    const actions: CodeAction[] = []
    for (const info of body) {
      if (!info.inlineable) {
        const codeAction: CodeAction = {
          title: info.description,
          kind: CodeActionKind.Refactor
        }
        codeAction.command = {
          title: info.description,
          command: SelectRefactorCommand.ID,
          arguments: [document, file, info, rangeOrSelection]
        }
        actions.push(codeAction)
      } else {
        for (const action of info.actions) {
          actions.push(
            this.refactorActionToCodeAction(
              action,
              document,
              file,
              info,
              rangeOrSelection
github neoclide / coc-tsserver / src / server / features / refactor.ts View on Github external
let label = info.actions[idx].name
    if (!label) return false
    return this.doRefactoring.execute(
      document,
      file,
      info.name,
      label,
      range
    )
  }
}

export default class TypeScriptRefactorProvider implements CodeActionProvider {
  private static readonly extractFunctionKind = CodeActionKind.RefactorExtract + '.function'
  private static readonly extractConstantKind = CodeActionKind.RefactorExtract + '.constant'
  private static readonly moveKind = CodeActionKind.Refactor + '.move'

  constructor(
    private readonly client: ITypeScriptServiceClient,
    private readonly formattingOptionsManager: FormattingOptionsManager,
  ) {
    const doRefactoringCommand = commands.register(
      new ApplyRefactoringCommand(this.client)
    )
    commands.register(new SelectRefactorCommand(doRefactoringCommand))
  }

  public static readonly metadata: CodeActionProviderMetadata = {
    providedCodeActionKinds: [CodeActionKind.Refactor]
  }

  public async provideCodeActions(
github neoclide / coc.nvim / src / extensions / tsserver / features / refactor.ts View on Github external
let label = info.actions[idx].name
    if (!label) return false
    return this.doRefactoring.execute(
      document,
      file,
      info.name,
      label,
      range
    )
  }
}

export default class TypeScriptRefactorProvider implements CodeActionProvider {
  private static readonly extractFunctionKind = CodeActionKind.RefactorExtract + '.function'
  private static readonly extractConstantKind = CodeActionKind.RefactorExtract + '.constant'
  private static readonly moveKind = CodeActionKind.Refactor + '.move'

  constructor(
    private readonly client: ITypeScriptServiceClient,
    private readonly formattingOptionsManager: FormattingOptionsManager,
  ) {
    const doRefactoringCommand = commandManager.register(
      new ApplyRefactoringCommand(this.client)
    )
    commandManager.register(new SelectRefactorCommand(doRefactoringCommand))
  }

  public static readonly metadata: CodeActionProviderMetadata = {
    providedCodeActionKinds: [CodeActionKind.Refactor]
  }

  public async provideCodeActions(
github neoclide / coc-tsserver / src / server / features / refactor.ts View on Github external
private static readonly extractFunctionKind = CodeActionKind.RefactorExtract + '.function'
  private static readonly extractConstantKind = CodeActionKind.RefactorExtract + '.constant'
  private static readonly moveKind = CodeActionKind.Refactor + '.move'

  constructor(
    private readonly client: ITypeScriptServiceClient,
    private readonly formattingOptionsManager: FormattingOptionsManager,
  ) {
    const doRefactoringCommand = commands.register(
      new ApplyRefactoringCommand(this.client)
    )
    commands.register(new SelectRefactorCommand(doRefactoringCommand))
  }

  public static readonly metadata: CodeActionProviderMetadata = {
    providedCodeActionKinds: [CodeActionKind.Refactor]
  }

  public async provideCodeActions(
    document: TextDocument,
    range: Range,
    context: CodeActionContext,
    token: CancellationToken
  ): Promise {
    if (!this.shouldTrigger(context)) {
      return undefined
    }
    const file = this.client.toPath(document.uri)
    if (!file) return undefined
    await this.formattingOptionsManager.ensureConfigurationForDocument(document)
    const args: Proto.GetApplicableRefactorsRequestArgs = typeConverters.Range.toFileRangeRequestArgs(
      file,
github neoclide / coc-tsserver / src / server / features / refactor.ts View on Github external
private static getKind(refactor: Proto.RefactorActionInfo): string {
    if (refactor.name.startsWith('function_')) {
      return TypeScriptRefactorProvider.extractFunctionKind
    } else if (refactor.name.startsWith('constant_')) {
      return TypeScriptRefactorProvider.extractConstantKind
    } else if (refactor.name.startsWith('Move')) {
      return TypeScriptRefactorProvider.moveKind
    }
    return CodeActionKind.Refactor
  }
}
github neoclide / coc-tsserver / src / server / languageProvider.ts View on Github external
let conf = fileConfigurationManager.getLanguageConfiguration(this.id)

    if (this.client.apiVersion.gte(API.v290)
      && conf.get('updateImportsOnFileMove.enable')) {
      this.disposables.push(
        new UpdateImportsOnFileRenameHandler(client, this.fileConfigurationManager, this.id)
      )
    }

    if (this.client.apiVersion.gte(API.v240)) {
      this.disposables.push(
        languages.registerCodeActionProvider(
          languageIds,
          new RefactorProvider(client, this.fileConfigurationManager),
          'tsserver',
          [CodeActionKind.Refactor]))
    }

    this.disposables.push(
      languages.registerCodeActionProvider(
        languageIds,
        new InstallModuleProvider(client),
        'tsserver')
    )

    this.disposables.push(
      languages.registerCodeActionProvider(
        languageIds,
        new QuickfixProvider(client),
        'tsserver',
        [CodeActionKind.QuickFix]))
github neoclide / coc-tsserver / src / server / features / refactor.ts View on Github external
private convertApplicableRefactors(
    body: Proto.ApplicableRefactorInfo[],
    document: TextDocument,
    file: string,
    rangeOrSelection: Range
  ): CodeAction[] {
    const actions: CodeAction[] = []
    for (const info of body) {
      if (!info.inlineable) {
        const codeAction: CodeAction = {
          title: info.description,
          kind: CodeActionKind.Refactor
        }
        codeAction.command = {
          title: info.description,
          command: SelectRefactorCommand.ID,
          arguments: [document, file, info, rangeOrSelection]
        }
        actions.push(codeAction)
      } else {
        for (const action of info.actions) {
          actions.push(
            this.refactorActionToCodeAction(
              action,
              document,
              file,
              info,
              rangeOrSelection
github neoclide / coc.nvim / src / extensions / tsserver / features / refactor.ts View on Github external
private shouldTrigger(context: CodeActionContext): boolean {
    if (
      context.only &&
      context.only.indexOf(CodeActionKind.Refactor) == -1
    ) {
      return false
    }
    return true
  }