diff --git a/src/__tests__/handler/codeActions.test.ts b/src/__tests__/handler/codeActions.test.ts index 9a07f1de8a7..d299f2d1c11 100644 --- a/src/__tests__/handler/codeActions.test.ts +++ b/src/__tests__/handler/codeActions.test.ts @@ -323,7 +323,7 @@ describe('handler codeActions', () => { let edit = { changes: { [doc.uri]: edits } } let action = CodeAction.create('code fix', edit, CodeActionKind.QuickFix) currActions = [action, CodeAction.create('foo')] - let promise = codeActions.doCodeAction(null) + let promise = codeActions.doCodeAction(null, []) await helper.waitFloat() let ids = await nvim.call('coc#float#get_float_win_list') as number[] expect(ids.length).toBeGreaterThan(0) @@ -398,7 +398,7 @@ describe('handler codeActions', () => { let spy = jest.spyOn(window, 'showQuickpick').mockImplementation(() => { return Promise.resolve(-1) }) - await codeActions.doCodeAction(null) + await codeActions.doCodeAction(null, []) spy.mockRestore() helper.updateConfiguration('coc.preferences.floatActions', true) }) diff --git a/src/extension/manager.ts b/src/extension/manager.ts index 1d8d2cde349..807f8313ccd 100644 --- a/src/extension/manager.ts +++ b/src/extension/manager.ts @@ -256,7 +256,7 @@ export class ExtensionManager { * Activate extension, throw error if disabled or doesn't exist. * Returns true if extension successfully activated. */ - public async activate(id): Promise { + public async activate(id: string): Promise { let item = this.extensions.get(id) if (!item) throw new Error(`Extension ${id} not registered!`) let { extension } = item @@ -265,7 +265,7 @@ export class ExtensionManager { return extension.isActive === true } - public async deactivate(id): Promise { + public async deactivate(id: string): Promise { let item = this.extensions.get(id) if (!item || !item.extension.isActive) return await Promise.resolve(item.deactivate()) diff --git a/src/handler/codeActions.ts b/src/handler/codeActions.ts index 38130ae7683..a361a20070f 100644 --- a/src/handler/codeActions.ts +++ b/src/handler/codeActions.ts @@ -79,7 +79,7 @@ export default class CodeActions { return workspace.initialConfiguration.get('coc.preferences.floatActions', true) } - public async doCodeAction(mode: string | null, only?: CodeActionKind[] | string, showDisable = false): Promise { + public async doCodeAction(mode: string | null, only: CodeActionKind[] | string, showDisable = false): Promise { let { doc } = await this.handler.getCurrentState() let range: Range | undefined if (mode) range = await window.getSelectedRange(mode) diff --git a/src/handler/hover.ts b/src/handler/hover.ts index 9b8c346d39d..91449d0bed6 100644 --- a/src/handler/hover.ts +++ b/src/handler/hover.ts @@ -17,8 +17,7 @@ import { characterIndex } from '../util/string' import window from '../window' import workspace from '../workspace' import { HandlerDelegate } from './types' - -export type HoverTarget = 'float' | 'preview' | 'echo' +import { HoverTarget } from '../plugin' interface HoverConfig { target: HoverTarget diff --git a/src/plugin.ts b/src/plugin.ts index 63ab737126b..2b006026ae8 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,6 +1,6 @@ 'use strict' import { Neovim } from './neovim' -import { CodeActionKind, InsertTextMode, Range } from 'vscode-languageserver-types' +import { CallHierarchyItem, CodeAction, CodeActionKind, InsertTextMode, Range, WorkspaceSymbol } from 'vscode-languageserver-types' import commandManager from './commands' import completion, { Completion } from './completion' import sources from './completion/sources' @@ -19,6 +19,8 @@ import window from './window' import workspace, { Workspace } from './workspace' const logger = createLogger('plugin') +export type HoverTarget = 'float' | 'preview' | 'echo' + export default class Plugin { private ready = false private initialized = false @@ -58,7 +60,7 @@ export default class Plugin { this.addAction('openLog', () => this.handler.workspace.openLog()) this.addAction('attach', () => workspace.attach()) this.addAction('detach', () => workspace.detach()) - this.addAction('doKeymap', (key, defaultReturn) => this.handler.workspace.doKeymap(key, defaultReturn)) + this.addAction('doKeymap', (key: string, defaultReturn: string) => this.handler.workspace.doKeymap(key, defaultReturn)) this.addAction('registerExtensions', (...folders: string[]) => extensions.manager.loadExtension(folders), 'registExtensions') this.addAction('snippetCheck', (checkExpand: boolean, checkJump: boolean) => this.handler.workspace.snippetCheck(checkExpand, checkJump)) this.addAction('snippetInsert', (range: Range, newText: string, mode?: InsertTextMode, ultisnip?: UltiSnippetOption) => snippetManager.insertSnippet(newText, true, range, mode, ultisnip, true)) @@ -76,7 +78,7 @@ export default class Plugin { this.addAction('openList', (...args: string[]) => listManager.start(args)) this.addAction('listNames', () => listManager.names) this.addAction('listDescriptions', () => listManager.descriptions) - this.addAction('listLoadItems', name => listManager.loadItems(name)) + this.addAction('listLoadItems', (name: string) => listManager.loadItems(name)) this.addAction('listResume', (name?: string) => listManager.resume(name)) this.addAction('listCancel', () => listManager.cancel(true)) this.addAction('listPrev', (name?: string) => listManager.previous(name)) @@ -93,58 +95,58 @@ export default class Plugin { this.addAction('colorPresentation', () => this.handler.colors.pickPresentation()) this.addAction('highlight', () => this.handler.documentHighlighter.highlight()) this.addAction('fold', (kind?: string) => this.handler.fold.fold(kind)) - this.addAction('startCompletion', option => completion.startCompletion(option)) + this.addAction('startCompletion', (option: { source?: string }) => completion.startCompletion(option)) this.addAction('sourceStat', () => sources.sourceStats()) - this.addAction('refreshSource', name => sources.refresh(name)) - this.addAction('toggleSource', name => sources.toggleSource(name)) - this.addAction('diagnosticRefresh', bufnr => diagnosticManager.refresh(bufnr)) - this.addAction('diagnosticInfo', target => diagnosticManager.echoCurrentMessage(target)) - this.addAction('diagnosticToggle', enable => diagnosticManager.toggleDiagnostic(enable)) - this.addAction('diagnosticToggleBuffer', (bufnr, enable) => diagnosticManager.toggleDiagnosticBuffer(bufnr, enable)) - this.addAction('diagnosticNext', severity => diagnosticManager.jumpNext(severity)) - this.addAction('diagnosticPrevious', severity => diagnosticManager.jumpPrevious(severity)) + this.addAction('refreshSource', (name: string) => sources.refresh(name)) + this.addAction('toggleSource', (name: string) => sources.toggleSource(name)) + this.addAction('diagnosticRefresh', (bufnr?: number) => diagnosticManager.refresh(bufnr)) + this.addAction('diagnosticInfo', (target?: string) => diagnosticManager.echoCurrentMessage(target)) + this.addAction('diagnosticToggle', (enable?: number) => diagnosticManager.toggleDiagnostic(enable)) + this.addAction('diagnosticToggleBuffer', (bufnr?: number, enable?: number) => diagnosticManager.toggleDiagnosticBuffer(bufnr, enable)) + this.addAction('diagnosticNext', (severity?: string) => diagnosticManager.jumpNext(severity)) + this.addAction('diagnosticPrevious', (severity?: string) => diagnosticManager.jumpPrevious(severity)) this.addAction('diagnosticPreview', () => diagnosticManager.preview()) this.addAction('diagnosticList', () => diagnosticManager.getDiagnosticList()) this.addAction('diagnosticRelatedInformation', () => diagnosticManager.relatedInformation()) - this.addAction('findLocations', (id, method, params, openCommand) => this.handler.locations.findLocations(id, method, params, openCommand)) + this.addAction('findLocations', (id: string, method: string, params: any, openCommand: string) => this.handler.locations.findLocations(id, method, params, openCommand)) this.addAction('getTagList', () => this.handler.locations.getTagList()) this.addAction('definitions', () => this.handler.locations.definitions()) this.addAction('declarations', () => this.handler.locations.declarations()) this.addAction('implementations', () => this.handler.locations.implementations()) this.addAction('typeDefinitions', () => this.handler.locations.typeDefinitions()) - this.addAction('references', excludeDeclaration => this.handler.locations.references(excludeDeclaration)) - this.addAction('jumpUsed', openCommand => this.handler.locations.gotoReferences(openCommand, false)) - this.addAction('jumpDefinition', openCommand => this.handler.locations.gotoDefinition(openCommand)) - this.addAction('jumpReferences', openCommand => this.handler.locations.gotoReferences(openCommand)) - this.addAction('jumpTypeDefinition', openCommand => this.handler.locations.gotoTypeDefinition(openCommand)) - this.addAction('jumpDeclaration', openCommand => this.handler.locations.gotoDeclaration(openCommand)) - this.addAction('jumpImplementation', openCommand => this.handler.locations.gotoImplementation(openCommand)) - this.addAction('doHover', hoverTarget => this.handler.hover.onHover(hoverTarget)) - this.addAction('definitionHover', hoverTarget => this.handler.hover.definitionHover(hoverTarget)) - this.addAction('getHover', loc => this.handler.hover.getHover(loc)) + this.addAction('references', (excludeDeclaration?: boolean) => this.handler.locations.references(excludeDeclaration)) + this.addAction('jumpUsed', (openCommand?: string) => this.handler.locations.gotoReferences(openCommand, false)) + this.addAction('jumpDefinition', (openCommand?: string | false) => this.handler.locations.gotoDefinition(openCommand)) + this.addAction('jumpReferences', (openCommand?: string | false) => this.handler.locations.gotoReferences(openCommand)) + this.addAction('jumpTypeDefinition', (openCommand?: string | false) => this.handler.locations.gotoTypeDefinition(openCommand)) + this.addAction('jumpDeclaration', (openCommand?: string | false) => this.handler.locations.gotoDeclaration(openCommand)) + this.addAction('jumpImplementation', (openCommand?: string | false) => this.handler.locations.gotoImplementation(openCommand)) + this.addAction('doHover', (hoverTarget: HoverTarget) => this.handler.hover.onHover(hoverTarget)) + this.addAction('definitionHover', (hoverTarget: HoverTarget) => this.handler.hover.definitionHover(hoverTarget)) + this.addAction('getHover', (loc?: { bufnr?: number, line: number, col: number }) => this.handler.hover.getHover(loc)) this.addAction('showSignatureHelp', () => this.handler.signature.triggerSignatureHelp()) this.addAction('documentSymbols', (bufnr?: number) => this.handler.symbols.getDocumentSymbols(bufnr)) this.addAction('symbolRanges', () => this.handler.documentHighlighter.getSymbolsRanges()) this.addAction('selectionRanges', () => this.handler.selectionRange.getSelectionRanges()) - this.addAction('rangeSelect', (visualmode, forward) => this.handler.selectionRange.selectRange(visualmode, forward)) - this.addAction('rename', newName => this.handler.rename.rename(newName)) - this.addAction('getWorkspaceSymbols', input => this.handler.symbols.getWorkspaceSymbols(input)) - this.addAction('resolveWorkspaceSymbol', symbolInfo => this.handler.symbols.resolveWorkspaceSymbol(symbolInfo)) - this.addAction('formatSelected', mode => this.handler.format.formatCurrentRange(mode)) + this.addAction('rangeSelect', (visualmode: string, forward: boolean) => this.handler.selectionRange.selectRange(visualmode, forward)) + this.addAction('rename', (newName?: string) => this.handler.rename.rename(newName)) + this.addAction('getWorkspaceSymbols', (input: string) => this.handler.symbols.getWorkspaceSymbols(input)) + this.addAction('resolveWorkspaceSymbol', (symbolInfo: WorkspaceSymbol) => this.handler.symbols.resolveWorkspaceSymbol(symbolInfo)) + this.addAction('formatSelected', (mode: string) => this.handler.format.formatCurrentRange(mode)) this.addAction('format', () => this.handler.format.formatCurrentBuffer()) this.addAction('commands', () => commandManager.commandList) this.addAction('services', () => services.getServiceStats()) - this.addAction('toggleService', name => services.toggle(name)) - this.addAction('codeAction', (mode, only, noExclude) => this.handler.codeActions.doCodeAction(mode, only, noExclude)) + this.addAction('toggleService', (name: string) => services.toggle(name)) + this.addAction('codeAction', (mode: string | null, only: CodeActionKind[] | string, noExclude: boolean) => this.handler.codeActions.doCodeAction(mode, only, noExclude)) this.addAction('organizeImport', () => this.handler.codeActions.organizeImport()) this.addAction('fixAll', () => this.handler.codeActions.doCodeAction(null, [CodeActionKind.SourceFixAll])) - this.addAction('doCodeAction', codeAction => this.handler.codeActions.applyCodeAction(codeAction)) - this.addAction('codeActions', (mode, only) => this.handler.codeActions.getCurrentCodeActions(mode, only)) - this.addAction('quickfixes', mode => this.handler.codeActions.getCurrentCodeActions(mode, [CodeActionKind.QuickFix])) + this.addAction('doCodeAction', (codeAction: CodeAction) => this.handler.codeActions.applyCodeAction(codeAction)) + this.addAction('codeActions', (mode?: string, only?: CodeActionKind[]) => this.handler.codeActions.getCurrentCodeActions(mode, only)) + this.addAction('quickfixes', (mode?: string) => this.handler.codeActions.getCurrentCodeActions(mode, [CodeActionKind.QuickFix])) this.addAction('codeLensAction', () => this.handler.codeLens.doAction()) this.addAction('doQuickfix', () => this.handler.codeActions.doQuickfix()) this.addAction('search', (...args: string[]) => this.handler.refactor.search(args)) - this.addAction('saveRefactor', bufnr => this.handler.refactor.save(bufnr)) + this.addAction('saveRefactor', (bufnr: number) => this.handler.refactor.save(bufnr)) this.addAction('refactor', () => this.handler.refactor.doRefactor()) this.addAction('runCommand', (...args: any[]) => this.handler.commands.runCommand(...args)) this.addAction('repeatCommand', () => this.handler.commands.repeat()) @@ -153,22 +155,22 @@ export default class Plugin { this.addAction('extensionStats', () => extensions.getExtensionStates()) this.addAction('loadedExtensions', () => extensions.manager.loadedExtensions) this.addAction('watchExtension', (id: string) => extensions.manager.watchExtension(id)) - this.addAction('activeExtension', name => extensions.manager.activate(name)) - this.addAction('deactivateExtension', name => extensions.manager.deactivate(name)) - this.addAction('reloadExtension', name => extensions.manager.reloadExtension(name)) - this.addAction('toggleExtension', name => extensions.manager.toggleExtension(name)) + this.addAction('activeExtension', (name: string) => extensions.manager.activate(name)) + this.addAction('deactivateExtension', (name: string) => extensions.manager.deactivate(name)) + this.addAction('reloadExtension', (name: string) => extensions.manager.reloadExtension(name)) + this.addAction('toggleExtension', (name: string) => extensions.manager.toggleExtension(name)) this.addAction('uninstallExtension', (...args: string[]) => extensions.manager.uninstallExtensions(args)) this.addAction('getCurrentFunctionSymbol', () => this.handler.symbols.getCurrentFunctionSymbol()) this.addAction('showOutline', (keep?: number) => this.handler.symbols.showOutline(keep)) this.addAction('hideOutline', () => this.handler.symbols.hideOutline()) this.addAction('getWordEdit', () => this.handler.rename.getWordEdit()) - this.addAction('addCommand', cmd => this.handler.commands.addVimCommand(cmd)) - this.addAction('addRanges', ranges => this.cursors.addRanges(ranges)) + this.addAction('addCommand', (cmd: { id: string, cmd: string, title?: string }) => this.handler.commands.addVimCommand(cmd)) + this.addAction('addRanges', (ranges: Range[]) => this.cursors.addRanges(ranges)) this.addAction('currentWorkspacePath', () => workspace.rootPath) - this.addAction('selectCurrentPlaceholder', triggerAutocmd => snippetManager.selectCurrentPlaceholder(!!triggerAutocmd)) - this.addAction('codeActionRange', (start, end, only) => this.handler.codeActions.codeActionRange(start, end, only)) - this.addAction('incomingCalls', item => this.handler.callHierarchy.getIncoming(item)) - this.addAction('outgoingCalls', item => this.handler.callHierarchy.getOutgoing(item)) + this.addAction('selectCurrentPlaceholder', (triggerAutocmd: boolean) => snippetManager.selectCurrentPlaceholder(!!triggerAutocmd)) + this.addAction('codeActionRange', (start: number, end: number, only?: string) => this.handler.codeActions.codeActionRange(start, end, only)) + this.addAction('incomingCalls', (item?: CallHierarchyItem) => this.handler.callHierarchy.getIncoming(item)) + this.addAction('outgoingCalls', (item?: CallHierarchyItem) => this.handler.callHierarchy.getOutgoing(item)) this.addAction('showIncomingCalls', () => this.handler.callHierarchy.showCallHierarchyTree('incoming')) this.addAction('showOutgoingCalls', () => this.handler.callHierarchy.showCallHierarchyTree('outgoing')) this.addAction('showSuperTypes', () => this.handler.typeHierarchy.showTypeHierarchyTree('supertypes'))