From 1e7abfa217917cd4210e8754db6bfcd60859a2c2 Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Tue, 10 Dec 2024 11:16:01 +0800 Subject: [PATCH] feat(scope): ensureDocument can accept bufnr (#5219) Closes #5218 --- doc/coc.txt | 4 ++-- history.md | 5 +++++ src/handler/workspace.ts | 4 ++-- src/plugin.ts | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/doc/coc.txt b/doc/coc.txt index 020ec0a1ef1..b50459db0b5 100644 --- a/doc/coc.txt +++ b/doc/coc.txt @@ -2448,9 +2448,9 @@ Acceptable {action} names for |CocAction()| and |CocActionAsync()|. Add {folder} to workspace folders, {folder} should be exists directory on file system. -"ensureDocument" *CocAction('ensureDocument')* +"ensureDocument" [{bufnr}] *CocAction('ensureDocument')* - Ensure current document is attached to coc.nvim + Ensure current or specified document is attached to coc.nvim |coc-document-attached|, should be used when you need invoke action of current document on buffer create. diff --git a/history.md b/history.md index d9b0c2bc6cc..d1f235be593 100644 --- a/history.md +++ b/history.md @@ -1,3 +1,8 @@ +# 2024-12-10 + +- Floating window can be set to fixed position, try `diagnostic.floatConfig` +- `ensureDocument` and `hasProvider` support to accept specified bufnr + # 2024-11-29 - Increase `g:coc_highlight_maximum_count` default to 500 for better performance. diff --git a/src/handler/workspace.ts b/src/handler/workspace.ts index 39b6ea4b3e5..526c3351680 100644 --- a/src/handler/workspace.ts +++ b/src/handler/workspace.ts @@ -231,8 +231,8 @@ export default class WorkspaceHandler { } } - public async ensureDocument(): Promise { - let doc = await workspace.document + public async ensureDocument(bufnr?: number): Promise { + let doc = bufnr ? workspace.getDocument(bufnr) : await workspace.document return doc && doc.attached } diff --git a/src/plugin.ts b/src/plugin.ts index ffb914d259a..63ab737126b 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -50,7 +50,7 @@ export default class Plugin { void window.showInformationMessage(`Run :CocInstall coc-json for json intellisense`) }) this.addAction('rootPatterns', (bufnr: number) => this.handler.workspace.getRootPatterns(bufnr)) - this.addAction('ensureDocument', () => this.handler.workspace.ensureDocument()) + this.addAction('ensureDocument', (bufnr?: number) => this.handler.workspace.ensureDocument(bufnr)) this.addAction('addWorkspaceFolder', (folder: string) => this.handler.workspace.addWorkspaceFolder(folder)) this.addAction('removeWorkspaceFolder', (folder: string) => this.handler.workspace.removeWorkspaceFolder(folder)) this.addAction('getConfig', (key: string) => this.handler.workspace.getConfiguration(key))