Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(handler): hasProvider can accept bufnr #4714

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2381,16 +2381,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