Skip to content

Commit

Permalink
Merge branch 'main' into bobbrow/extraQuotes
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbrow authored Oct 30, 2024
2 parents 7615539 + e45dbce commit f6e5bab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6511,7 +6511,7 @@
"translations-generate": "set NODE_OPTIONS=--no-experimental-fetch && gulp translations-generate",
"translations-import": "gulp translations-import",
"import-edge-strings": "ts-node -T ./.scripts/import_edge_strings.ts",
"prep:dts": "yarn verify dts --quiet || (npx vscode-dts dev && npx vscode-dts main)",
"prep:dts": "yarn verify dts --quiet || (npx @vscode/dts dev && npx @vscode/dts main)",
"build": "yarn prep:dts && echo [Building TypeScript code] && tsc --build tsconfig.json"
},
"devDependencies": {
Expand Down
62 changes: 18 additions & 44 deletions Extension/src/LanguageServer/protocolFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as path from 'path';
import * as vscode from 'vscode';
import { Middleware } from 'vscode-languageclient';
import * as util from '../common';
import { logAndReturn } from '../Utility/Async/returns';
import { Client } from './client';
import { clients } from './extension';
import { shouldChangeFromCToCpp } from './utils';
Expand All @@ -18,14 +19,8 @@ export const ServerCancelled: number = -32802;
let anyFileOpened: boolean = false;

export function createProtocolFilter(): Middleware {
// Disabling lint for invoke handlers
const invoke1 = (a: any, next: (a: any) => any): any => clients.ActiveClient.enqueue(() => next(a));
const invoke2 = (a: any, b: any, next: (a: any, b: any) => any): any => clients.ActiveClient.enqueue(() => next(a, b));
const invoke3 = (a: any, b: any, c: any, next: (a: any, b: any, c: any) => any): any => clients.ActiveClient.enqueue(() => next(a, b, c));
const invoke4 = (a: any, b: any, c: any, d: any, next: (a: any, b: any, c: any, d: any) => any): any => clients.ActiveClient.enqueue(() => next(a, b, c, d));

return {
didOpen: async (document, sendMessage) => clients.ActiveClient.enqueue(async () => {
didOpen: async (document, sendMessage) => {
if (!util.isCpp(document)) {
return;
}
Expand All @@ -41,62 +36,41 @@ export function createProtocolFilter(): Middleware {
const mappingString: string = baseFileName + "@" + document.fileName;
client.addFileAssociations(mappingString, "cpp");
client.sendDidChangeSettings();
document = await vscode.languages.setTextDocumentLanguage(document, "cpp");
// This will cause the file to be closed and reopened.
void vscode.languages.setTextDocumentLanguage(document, "cpp");
return;
}
// client.takeOwnership() will call client.TrackedDocuments.add() again, but that's ok. It's a Set.
client.onDidOpenTextDocument(document);
client.takeOwnership(document);
await sendMessage(document);

// For a file already open when we activate, sometimes we don't get any notifications about visible
// or active text editors, visible ranges, or text selection. As a workaround, we trigger
// onDidChangeVisibleTextEditors here, only for the first file opened.
if (!anyFileOpened) {
anyFileOpened = true;
const cppEditors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => util.isCpp(e.document));
await client.onDidChangeVisibleTextEditors(cppEditors);
}
void sendMessage(document).then(() => {
// For a file already open when we activate, sometimes we don't get any notifications about visible
// or active text editors, visible ranges, or text selection. As a workaround, we trigger
// onDidChangeVisibleTextEditors here, only for the first file opened.
if (!anyFileOpened) {
anyFileOpened = true;
const cppEditors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => util.isCpp(e.document));
client.onDidChangeVisibleTextEditors(cppEditors).catch(logAndReturn.undefined);
}
});
}
}
}),
didChange: invoke1,
willSave: invoke1,
},
willSaveWaitUntil: async (event, sendMessage) => {
// await clients.ActiveClient.ready;
// Don't use awaitUntilLanguageClientReady.
// Otherwise, the message can be delayed too long.
const me: Client = clients.getClientFor(event.document.uri);
if (me.TrackedDocuments.has(event.document.uri.toString())) {
return sendMessage(event);
}
return [];
},
didSave: invoke1,
didClose: async (document, sendMessage) => clients.ActiveClient.enqueue(async () => {
didClose: async (document, sendMessage) => {
const me: Client = clients.getClientFor(document.uri);
const uriString: string = document.uri.toString();
if (me.TrackedDocuments.has(uriString)) {
me.onDidCloseTextDocument(document);
me.TrackedDocuments.delete(uriString);
await sendMessage(document);
}
}),
provideCompletionItem: invoke4,
resolveCompletionItem: invoke2,
provideHover: async (document, position, token, next: (document: any, position: any, token: any) => any) => clients.ActiveClient.enqueue(async () => {
const me: Client = clients.getClientFor(document.uri);
if (me.TrackedDocuments.has(document.uri.toString())) {
return next(document, position, token);
void sendMessage(document);
}
return null;
}),
provideSignatureHelp: invoke4,
provideDefinition: invoke3,
provideReferences: invoke4,
provideDocumentHighlights: invoke3,
provideDeclaration: invoke3,
workspace: {
didChangeConfiguration: invoke1
}
};
}

0 comments on commit f6e5bab

Please sign in to comment.