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

workspace.onDidOpenTextDocument cannot work #5200

Closed
Freed-Wu opened this issue Nov 24, 2024 · 6 comments
Closed

workspace.onDidOpenTextDocument cannot work #5200

Freed-Wu opened this issue Nov 24, 2024 · 6 comments

Comments

@Freed-Wu
Copy link

Result from CocInfo

versions

vim version: NVIM v0.10.2
node version: v20.18.0
coc.nvim version: 0.0.82-9fd85781 2024-09-21 00:59:00 +0900
coc.nvim directory: /home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release
term: tmux
platform: linux

Log of coc.nvim

2024-11-24T22:30:58.650 INFO (pid:1067148) [plugin] - coc.nvim initialized with node: v20.18.0 after 78
2024-11-24T22:30:58.669 INFO (pid:1067148) [core-watchman] - watchman watching project: /dev/shm/coc-test

Describe the bug

import { ExtensionContext, window, workspace } from 'coc.nvim';

export async function activate(context: ExtensionContext): Promise<void> {

  context.subscriptions.push(workspace.onDidOpenTextDocument(event => {
    window.showInformationMessage("test");
  }));

}
#!/usr/bin/env -S vi -u
set runtimepath=$VIMRUNTIME
set runtimepath+=~/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release
let s:root = fnamemodify(expand('<sfile>'), ':p:h:h')
execute 'set runtimepath+=' . s:root
let g:coc_config_home = '.'
let g:coc_data_home = s:root . '/node_modules/coc'
set formatexpr=CocAction('formatSelected')

Then

tests/test.vim tests/test.vim

Expected:

Display test after open test.vim

Actually:

Nothing happened.

@fannheyward
Copy link
Member

fannheyward commented Nov 25, 2024

I encountered this before; I remember that the event was fired before the extension was activated.

After extension activated, open document like :e foo will fire this event.

@fannheyward
Copy link
Member

A workaround for this:

export async function activate(context: ExtensionContext): Promise<void> {
  context.subscriptions.push(
    workspace.onDidOpenTextDocument(didOpenTextDocument),
  );

  workspace.documents.map((doc: Document) => {
    didOpenTextDocument(doc.textDocument);
  });
}

@Freed-Wu
Copy link
Author

Where is didOpenTextDocument?

@fannheyward
Copy link
Member

didOpenTextDocument

Custom example function.

The workspace.documents contains opened documents.

@Freed-Wu
Copy link
Author

Can you provide an entire solution includes didOpenTextDocument? I cannot make it work 😢

@fannheyward
Copy link
Member

Freed-Wu added a commit to Freed-Wu/coc-write-good that referenced this issue Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants