Skip to content

Commit

Permalink
pass triggerReason and kind for refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Nov 20, 2022
1 parent a70869e commit aca3359
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"keywords": [
"coc.nvim",
"tsserver",
"typescript"
"typescript",
"javascript"
],
"scripts": {
"prepare": "node esbuild.js"
Expand Down
15 changes: 10 additions & 5 deletions src/server/features/refactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CodeActionProvider, Uri, CodeActionProviderMetadata, commands, TextDocument, window, workspace } from 'coc.nvim'
import { CodeActionProvider, Uri, CodeActionProviderMetadata, commands, TextDocument, window, workspace, CodeActionTriggerKind } from 'coc.nvim'
import { CancellationToken, CodeAction, CodeActionContext, CodeActionKind, Range, WorkspaceEdit } from 'vscode-languageserver-protocol'
import { Command, registCommand } from '../commands'
import Proto from '../protocol'
Expand Down Expand Up @@ -126,13 +126,18 @@ export default class TypeScriptRefactorProvider implements CodeActionProvider {
if (!this.shouldTrigger(context)) {
return undefined
}
// context.triggerKind
const file = this.client.toPath(document.uri)
if (!file) return undefined
await this.formattingOptionsManager.ensureConfigurationForDocument(document, token)
const args: Proto.GetApplicableRefactorsRequestArgs = typeConverters.Range.toFileRangeRequestArgs(
file,
range
)
const args: Proto.GetApplicableRefactorsRequestArgs = {
...typeConverters.Range.toFileRangeRequestArgs(
file,
range
),
triggerReason: context.triggerKind === CodeActionTriggerKind.Invoked ? 'invoked' : 'implicit',
kind: Array.isArray(context.only) ? context.only[0] : undefined
}
let response
try {
response = await this.client.interruptGetErr(() => {
Expand Down

0 comments on commit aca3359

Please sign in to comment.