Await in protocol filter (#10306)
This commit is contained in:
@@ -5976,7 +5976,7 @@
|
||||
"ssh-config": "^4.1.0",
|
||||
"tmp": "^0.2.1",
|
||||
"vscode-cpptools": "^6.1.0",
|
||||
"vscode-languageclient": "^8.0.1",
|
||||
"vscode-languageclient": "^8.1.0-next.4",
|
||||
"vscode-nls": "^5.0.0",
|
||||
"vscode-tas-client": "^0.1.27",
|
||||
"which": "^2.0.2",
|
||||
|
||||
@@ -13,16 +13,14 @@ import { shouldChangeFromCToCpp } from './utils';
|
||||
|
||||
export function createProtocolFilter(): Middleware {
|
||||
// Disabling lint for invoke handlers
|
||||
const defaultHandler: (data: any, callback: (data: any) => Promise<void>) => Promise<void> = async (data, callback: (data: any) => void) => { clients.ActiveClient.notifyWhenLanguageClientReady(() => callback(data)); };
|
||||
// const invoke1 = async (a: any, next: (a: any) => any) => { await clients.ActiveClient.awaitUntilLanguageClientReady(); return next(a); };
|
||||
const invoke1 = async (a: any, next: (a: any) => any) => { await clients.ActiveClient.awaitUntilLanguageClientReady(); return next(a); };
|
||||
const invoke2 = async (a: any, b: any, next: (a: any, b: any) => any) => { await clients.ActiveClient.awaitUntilLanguageClientReady(); return next(a, b); };
|
||||
const invoke3 = async (a: any, b: any, c: any, next: (a: any, b: any, c: any) => any) => { await clients.ActiveClient.awaitUntilLanguageClientReady(); return next(a, b, c); };
|
||||
const invoke4 = async (a: any, b: any, c: any, d: any, next: (a: any, b: any, c: any, d: any) => any) => { await clients.ActiveClient.awaitUntilLanguageClientReady(); return next(a, b, c, d); };
|
||||
// const invoke5 = async (a: any, b: any, c: any, d: any, e: any, next: (a: any, b: any, c: any, d: any, e: any) => any) => { await clients.ActiveClient.awaitUntilLanguageClientReady(); return next(a, b, c, d, e); };
|
||||
/* tslint:enable */
|
||||
const invoke4 = async (a: any, b: any, c: any, d: any, next: (a: any, b: any, c: any, d: any) => any) => { await clients.ActiveClient.awaitUntilLanguageClientReady(); return next(a, b, c, d); }; /* tslint:enable */
|
||||
|
||||
return {
|
||||
didOpen: async (document, sendMessage) => {
|
||||
await clients.ActiveClient.awaitUntilLanguageClientReady();
|
||||
const editor: vscode.TextEditor | undefined = vscode.window.visibleTextEditors.find(e => e.document === document);
|
||||
if (editor) {
|
||||
// If the file was visible editor when we were activated, we will not get a call to
|
||||
@@ -34,28 +32,22 @@ export function createProtocolFilter(): Middleware {
|
||||
clients.timeTelemetryCollector.setDidOpenTime(document.uri);
|
||||
if (clients.checkOwnership(me, document)) {
|
||||
me.TrackedDocuments.add(document);
|
||||
const finishDidOpen = (doc: vscode.TextDocument) => {
|
||||
me.provideCustomConfiguration(doc.uri, undefined);
|
||||
sendMessage(doc);
|
||||
const finishDidOpen = async (doc: vscode.TextDocument) => {
|
||||
await me.provideCustomConfiguration(doc.uri, undefined);
|
||||
await sendMessage(doc);
|
||||
me.onDidOpenTextDocument(doc);
|
||||
if (editor && editor === vscode.window.activeTextEditor) {
|
||||
onDidChangeActiveTextEditor(editor);
|
||||
}
|
||||
};
|
||||
let languageChanged: boolean = false;
|
||||
if (document.languageId === "c" && shouldChangeFromCToCpp(document)) {
|
||||
const baesFileName: string = path.basename(document.fileName);
|
||||
const mappingString: string = baesFileName + "@" + document.fileName;
|
||||
me.addFileAssociations(mappingString, "cpp");
|
||||
me.sendDidChangeSettings();
|
||||
vscode.languages.setTextDocumentLanguage(document, "cpp").then((newDoc: vscode.TextDocument) => {
|
||||
finishDidOpen(newDoc);
|
||||
});
|
||||
languageChanged = true;
|
||||
}
|
||||
if (!languageChanged) {
|
||||
finishDidOpen(document);
|
||||
document = await vscode.languages.setTextDocumentLanguage(document, "cpp");
|
||||
}
|
||||
await finishDidOpen(document);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -69,36 +61,39 @@ export function createProtocolFilter(): Middleware {
|
||||
}
|
||||
},
|
||||
didChange: async (textDocumentChangeEvent, sendMessage) => {
|
||||
await clients.ActiveClient.awaitUntilLanguageClientReady();
|
||||
const me: Client = clients.getClientFor(textDocumentChangeEvent.document.uri);
|
||||
me.onDidChangeTextDocument(textDocumentChangeEvent);
|
||||
sendMessage(textDocumentChangeEvent);
|
||||
await sendMessage(textDocumentChangeEvent);
|
||||
},
|
||||
willSave: defaultHandler,
|
||||
willSave: invoke1,
|
||||
willSaveWaitUntil: async (event, sendMessage) => {
|
||||
// await clients.ActiveClient.awaitUntilLanguageClientReady();
|
||||
// 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)) {
|
||||
// Don't use me.requestWhenReady or notifyWhenLanguageClientReady;
|
||||
// otherwise, the message can be delayed too long.
|
||||
return sendMessage(event);
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
return [];
|
||||
},
|
||||
didSave: defaultHandler,
|
||||
didSave: invoke1,
|
||||
didClose: async (document, sendMessage) => {
|
||||
await clients.ActiveClient.awaitUntilLanguageClientReady();
|
||||
const me: Client = clients.getClientFor(document.uri);
|
||||
if (me.TrackedDocuments.has(document)) {
|
||||
me.onDidCloseTextDocument(document);
|
||||
me.TrackedDocuments.delete(document);
|
||||
sendMessage(document);
|
||||
await sendMessage(document);
|
||||
}
|
||||
},
|
||||
|
||||
provideCompletionItem: invoke4,
|
||||
resolveCompletionItem: invoke2,
|
||||
provideHover: (document, position, token, next: (document: any, position: any, token: any) => any) => {
|
||||
provideHover: async (document, position, token, next: (document: any, position: any, token: any) => any) => {
|
||||
await clients.ActiveClient.awaitUntilLanguageClientReady();
|
||||
const me: Client = clients.getClientFor(document.uri);
|
||||
if (clients.checkOwnership(me, document)) {
|
||||
return clients.ActiveClient.requestWhenReady(() => next(document, position, token));
|
||||
if (me.TrackedDocuments.has(document)) {
|
||||
return next(document, position, token);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@@ -106,10 +101,9 @@ export function createProtocolFilter(): Middleware {
|
||||
provideDefinition: invoke3,
|
||||
provideReferences: invoke4,
|
||||
provideDocumentHighlights: invoke3,
|
||||
provideDeclaration: invoke3
|
||||
// I believe the default handler will do the same thing.
|
||||
// workspace: {
|
||||
// didChangeConfiguration: (sections, sendMessage) => sendMessage(sections)
|
||||
// }
|
||||
provideDeclaration: invoke3,
|
||||
workspace: {
|
||||
didChangeConfiguration: invoke1
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+22
-22
@@ -3846,7 +3846,7 @@ mimic-fn@^2.1.0:
|
||||
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
|
||||
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==
|
||||
|
||||
[email protected], minimatch@^3.0.4, minimatch@^3.0.5:
|
||||
[email protected], minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^5.1.0:
|
||||
version "3.1.2"
|
||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
|
||||
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
|
||||
@@ -5930,32 +5930,32 @@ vscode-dts@^0.3.2:
|
||||
prompts "^2.1.0"
|
||||
rimraf "^3.0.0"
|
||||
|
||||
vscode-jsonrpc@8.0.1:
|
||||
version "8.0.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-8.0.1.tgz#f30b0625ebafa0fb3bc53e934ca47b706445e57e"
|
||||
integrity sha512-N/WKvghIajmEvXpatSzvTvOIz61ZSmOSa4BRA4pTLi+1+jozquQKP/MkaylP9iB68k73Oua1feLQvH3xQuigiQ==
|
||||
vscode-jsonrpc@8.1.0-next.5:
|
||||
version "8.1.0-next.5"
|
||||
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-8.1.0-next.5.tgz#93fede04082a05268c735b77dae1edbb31708f33"
|
||||
integrity sha512-9l9lB8gXW1kPECKLC5Goc41pFztSCfODY3dvGaNTJ0KfRgwKIUyIhEBSdlWT2IU4uL4Tcl/zcitpb+Lj6QP7aQ==
|
||||
|
||||
vscode-languageclient@^8.0.1:
|
||||
version "8.0.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-8.0.1.tgz#bf5535c4463a78daeaca0bcb4f5868aec86bb301"
|
||||
integrity sha512-9XoE+HJfaWvu7Y75H3VmLo5WLCtsbxEgEhrLPqwt7eyoR49lUIyyrjb98Yfa50JCMqF2cePJAEVI6oe2o1sIhw==
|
||||
vscode-languageclient@^8.1.0-next.4:
|
||||
version "8.1.0-next.4"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-8.1.0-next.4.tgz#f56aae6350cb7602d3ac60f9cdf0c7b1bf5feb79"
|
||||
integrity sha512-dwo3Vf1aAb3o62mDhLHRGqYaLAYWN5RXAbHKL85Cs+yCJghxYzseuGGBvOUOH3BF5scnCU2BFrghekyP1xCUmQ==
|
||||
dependencies:
|
||||
minimatch "^3.0.4"
|
||||
semver "^7.3.5"
|
||||
vscode-languageserver-protocol "3.17.1"
|
||||
minimatch "^5.1.0"
|
||||
semver "^7.3.7"
|
||||
vscode-languageserver-protocol "3.17.3-next.4"
|
||||
|
||||
[email protected].1:
|
||||
version "3.17.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.1.tgz#e801762c304f740208b6c804a0cf21f2c87509ed"
|
||||
integrity sha512-BNlAYgQoYwlSgDLJhSG+DeA8G1JyECqRzM2YO6tMmMji3Ad9Mw6AW7vnZMti90qlAKb0LqAlJfSVGEdqMMNzKg==
|
||||
[email protected].3-next.4:
|
||||
version "3.17.3-next.4"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.3-next.4.tgz#28b30c556910e6d35080c764543b263eea16aa43"
|
||||
integrity sha512-G6XrjZGSe2LIo7uDa860JKX97sLKc1vQF4AU4SW8DI7NNVKxnCB+vEs8gYHmle7kD9v13PvFkDCBD5ApeONGNQ==
|
||||
dependencies:
|
||||
vscode-jsonrpc "8.0.1"
|
||||
vscode-languageserver-types "3.17.1"
|
||||
vscode-jsonrpc "8.1.0-next.5"
|
||||
vscode-languageserver-types "3.17.3-next.1"
|
||||
|
||||
[email protected]:
|
||||
version "3.17.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.1.tgz#c2d87fa7784f8cac389deb3ff1e2d9a7bef07e16"
|
||||
integrity sha512-K3HqVRPElLZVVPtMeKlsyL9aK0GxGQpvtAUTfX4k7+iJ4mc1M+JM+zQwkgGy2LzY0f0IAafe8MKqIkJrxfGGjQ==
|
||||
[email protected].3-next.1:
|
||||
version "3.17.3-next.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.3-next.1.tgz#0f9c65cf9d30b4236d4f20f2169b0ddbeb7646e7"
|
||||
integrity sha512-i7HXZs5CdNibVHXZORZw9m5Bm0mfXiGhD/tZv6f7arBtz4iatgiiHu2qInxn0fKeahhMJoBbp6irhsL9+E3UAA==
|
||||
|
||||
vscode-nls-dev@^4.0.0-next.1:
|
||||
version "4.0.0-next.1"
|
||||
|
||||
Reference in New Issue
Block a user