Skip to content

Commit

Permalink
feat(handler): hasProvider can accept bufnr (#4714)
Browse files Browse the repository at this point in the history
* feat(handler): hasProvider can accept bufnr

use current buffer if bufnr empty

* Update coc.vim

---------

Co-authored-by: Qiming zhao <[email protected]>
  • Loading branch information
fannheyward and chemzqm authored Aug 31, 2023
1 parent 18152f2 commit 4f3b4d9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
9 changes: 6 additions & 3 deletions doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2398,16 +2398,19 @@ CocActionAsync({action}, [...{args}, [{callback}]])

Checkout |coc-actions| for available actions.

CocHasProvider({feature}) *CocHasProvider()*
CocHasProvider({feature}, [{bufnr}]) *CocHasProvider()*

Check if provider exists for specified feature of current buffer.
Check if provider exists for specified feature of current or
{bufnr} buffer.
Supported features:

`rename` `onTypeEdit` `documentLink` `documentColor` `foldingRange`
`format` `codeAction` `workspaceSymbols` `formatRange` `hover`
`signature` `documentSymbol` `documentHighlight` `definition`
`declaration` `typeDefinition` `reference` `implementation` `codeLens`
`selectionRange`
`selectionRange` `formatOnType` `callHierarchy` `semanticTokens`
`semanticTokensRange` `linkedEditing` `inlayHint` `inlineValue`
`typeHierarchy`

CocTagFunc({pattern}, {flags}, {info}) *CocTagFunc()*

Expand Down
5 changes: 3 additions & 2 deletions plugin/coc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ function! CocAction(name, ...) abort
return coc#rpc#request(a:name, a:000)
endfunction

function! CocHasProvider(name) abort
return coc#rpc#request('hasProvider', [a:name])
function! CocHasProvider(name, ...) abort
let bufnr = empty(a:000) ? bufnr('%') : a:1
return coc#rpc#request('hasProvider', [a:name, bufnr])
endfunction

function! CocActionAsync(name, ...) abort
Expand Down
4 changes: 2 additions & 2 deletions src/handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ export default class Handler implements HandlerDelegate {
await this.codeActions.applyCodeAction(action)
}

public async hasProvider(id: string): Promise<boolean> {
let bufnr = await this.nvim.call('bufnr', '%') as number
public async hasProvider(id: string, bufnr?: number): Promise<boolean> {
if (!bufnr) bufnr = await this.nvim.call('bufnr', '%') as number
let doc = workspace.getDocument(bufnr)
if (!doc || !doc.attached) return false
return languages.hasProvider(id as ProviderName, doc.textDocument)
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class Plugin {
this.addAction('openLocalConfig', () => this.handler.workspace.openLocalConfig())
this.addAction('bufferCheck', () => this.handler.workspace.bufferCheck())
this.addAction('showInfo', () => this.handler.workspace.showInfo())
this.addAction('hasProvider', id => this.handler.hasProvider(id))
this.addAction('hasProvider', (id: string, bufnr?: number) => this.handler.hasProvider(id, bufnr))
this.addAction('cursorsSelect', (bufnr: number, kind: string, mode: string) => this.cursors.select(bufnr, kind, mode))
this.addAction('fillDiagnostics', (bufnr: number) => diagnosticManager.setLocationlist(bufnr))
this.addAction('commandList', () => this.handler.commands.getCommandList())
Expand Down

0 comments on commit 4f3b4d9

Please sign in to comment.