Activating my extension only in certain markdown files #901
-
Dear VSCode community, summary: we'd like our extension to activate only on markdown files with extension we have an extension (https://github.com/ejgallego/coq-lsp) for the Coq Interactive Theorem prover. This extension opens a side panel showing proof information files as it is customary in the Coq / Interactive Theorem Proving community. Our extension also supports literate markdown documents, that is to say, markdown documents with embedded Coq code snippets marked with Ideally, we'd like our extension to only activate for markdown files that have the However, we are struggling having our extension to activate automatically when a .mv file is opened. As of now, if we open an .mv file, the extension won't activate. Once the extension is activated by other means, it works fine with the .mv files. This is our contribution point: "contributes": {
"languages": [
{
"id": "markdown",
"aliases": [
"Markdown"
],
"extensions": [
".mv"
]
}
] Is it possible for us to do what we want? TIA! |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
First, we can set up the extension activation event: "activationEvents": [
"workspaceContains:**/*.mv"
] After the extension is activated, we can observe workspace event changes (for example: onDidOpenTextDocument) and we can perform real logic when the user opens a specific file. export function activate() {
vscode.workspace.onDidOpenTextDocument((textDocument) => {
if (
textDocument.languageId === "markdown" &&
textDocument.name.endsWith(".mv")
) {
// Do something
}
});
} Note that these codes have not been actually tested, so some content may not be completely accurate and are for reference only. Hope this helps you. |
Beta Was this translation helpful? Give feedback.
-
Hi @ejgallego , There is no single "files.associations": {
"*.mv": "markdown"
}, Using I'm not entirely sure, but I guess that this may work even if your Hope this helps |
Beta Was this translation helpful? Give feedback.
-
Hi @ejgallego, Does the follow responses help? |
Beta Was this translation helpful? Give feedback.
-
Hi all! Thanks a lot for all the amazing answers and help, I will look into them this upcomign week, I was offline for the past week. Something that has me wondering is that maybe there could be a bug in the new activation code. With the current code, when I activate the extension manually, it is properly activated on all the .mv files, so what it fails is the auto-activation, but I don't see how this should be the case. I'll test and report back soon, thanks for your patience. |
Beta Was this translation helpful? Give feedback.
-
Hi, I think |
Beta Was this translation helpful? Give feedback.
-
Hi folks, thanks again for all the help, but the more I think about this, the more it seems a bug (likely due to the new activation setup in 1.74). It makes little sense to me that the following happens as of now:
Isn't that strange? Dunno if I should file a bug.
Adding That would be a solution, however I am not sure this is not a bug; I'd like to determine if that looks like a bug before closing the question. What do you mean by "the events may not fire or may have fired before your extension activated" ? I'd like to add a test case for this, but I wasn't able to reproduce this behavior so I cannot test the code that would iterate the docs. Note that my extension is a LSP client one, so once activated the LSP client takes care of synching the editor, etc... |
Beta Was this translation helpful? Give feedback.
Hi, I think
onLanguage:markdown
would be a better event for you. Also, once activated make sure to loop through all open editors for mv files. For example if the user restores a window from the last time they had VS Code open, the events may not fire or may have fired before your extension activated.