recheck file when switching editors in vscode
This commit is contained in:
@@ -62,6 +62,8 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
|
|
||||||
function checkDocument(document: vscode.TextDocument) {
|
function checkDocument(document: vscode.TextDocument) {
|
||||||
const fileName = document.fileName;
|
const fileName = document.fileName;
|
||||||
|
if (!fileName.endsWith(".newt")) return;
|
||||||
|
|
||||||
// Is there a better way to do this? It will get fussy with quoting and all plus it's not visible to the user.
|
// Is there a better way to do this? It will get fussy with quoting and all plus it's not visible to the user.
|
||||||
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
|
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
|
||||||
const cwd = workspaceFolder
|
const cwd = workspaceFolder
|
||||||
@@ -144,10 +146,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
|
|
||||||
const runNewt = vscode.commands.registerCommand("newt-vscode.check", () => {
|
const runNewt = vscode.commands.registerCommand("newt-vscode.check", () => {
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
if (editor) {
|
if (editor) checkDocument(editor.document);
|
||||||
const document = editor.document;
|
|
||||||
if (document.fileName.endsWith(".newt")) checkDocument(document);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
@@ -268,17 +267,14 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
context.subscriptions.push(runNewt);
|
context.subscriptions.push(runNewt);
|
||||||
|
vscode.window.onDidChangeActiveTextEditor((editor) => {
|
||||||
vscode.workspace.onDidSaveTextDocument((document) => {
|
if (editor?.document.fileName.endsWith(".newt") && !editor.document.isDirty) {
|
||||||
if (document.fileName.endsWith(".newt"))
|
checkDocument(editor.document);
|
||||||
vscode.commands.executeCommand("newt-vscode.check");
|
}
|
||||||
});
|
});
|
||||||
vscode.workspace.onDidOpenTextDocument((document) => {
|
vscode.workspace.onDidSaveTextDocument(checkDocument);
|
||||||
if (document.fileName.endsWith(".newt"))
|
vscode.workspace.onDidOpenTextDocument(checkDocument);
|
||||||
vscode.commands.executeCommand("newt-vscode.check");
|
vscode.workspace.textDocuments.forEach(checkDocument);
|
||||||
});
|
|
||||||
for (let document of vscode.workspace.textDocuments)
|
|
||||||
if (document.fileName.endsWith(".newt")) checkDocument(document);
|
|
||||||
|
|
||||||
context.subscriptions.push(diagnosticCollection);
|
context.subscriptions.push(diagnosticCollection);
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
|
|||||||
Reference in New Issue
Block a user