Open WraithKenny opened 6 years ago
I know, and agree. Ref this and issues #9, #10, #11 and #12, I plan to refactor the plugin. I've also found that I should load config inside the registered command, as in https://github.com/Microsoft/vscode-extension-samples/blob/master/configuration-sample/src/extension.ts#L60-L72:
// Example 3: Reading Resource scoped configuration for a file
context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(e => {
// 1) Get the configured glob pattern value for the current file
const value = vscode.workspace.getConfiguration('', e.uri).get('conf.resource.insertEmptyLastLine');
// 2) Check if the current resource matches the glob pattern
const matches = value[e.fileName];
// 3) If matches, insert empty last line
if (matches) {
vscode.window.showInformationMessage('An empty line will be added to the document ' + e.fileName);
}
}));
I'm using this project to brush up on my scripting skills, and plan to do the refactoring in TypeScript.
Ah, OK. I'm willing to help for the same reasons, and why I made all the tickets (not trying to be annoying). If you'd rather work this out yourself for the experience, that's fine too, or I can submit pull requests, your option :)
In looking into examples and other repos (https://github.com/Microsoft/vscode-tslint/blob/master/tslint/extension.ts) it seems that multi-folder projects usually load configurations inside of the registered commands.
I can't tell if activation persists beyond one command execution, so I don't know that anything is saved by loading the configuration on activation, but if it is cached, than the configuration might be for the wrong folder on subsequent calls (if the next file is in another folder).
Refactoring this might be beneficial in another way, as instead of relying on
window.activeTextEditor
, theregisterTextEditorCommand
passestextEditor
as an arg that can be used (at least in that one command, less sure how to handle the other commands).