Improve performance of language detection (#130006)

* initial move to worker

* move event handling to the untitledTextEditorModel

* reuse simpleWorker interfaces and classes

* use correct path to languageDetection

* have vscode-languagedetection be outside of the asar

* add telemetry

* don't unpackage anything from languagedetection because it's not needed

* add an integration test

* some of Ben's feedback

* rework worker code to avoid duplication

* add isDisposed check

* fix test

* Isi and Ben feedback part 2

* use RunOnceScheduler instead and try to fix the test using events

* Ben feedback part 3

* bump distro
This commit is contained in:
Tyler James Leonhardt
2021-08-06 11:56:14 -07:00
committed by GitHub
parent 3d9899db8e
commit cfcda1c048
16 changed files with 541 additions and 213 deletions

View File

@@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as vscode from 'vscode';
import { asPromise, assertNoRpc, closeAllEditors } from '../utils';
suite('vscode - untitled automatic language detection', () => {
teardown(async function () {
assertNoRpc();
await closeAllEditors();
});
test('test automatic language detection works', async () => {
const doc = await vscode.workspace.openTextDocument();
const editor = await vscode.window.showTextDocument(doc);
assert.strictEqual(editor.document.languageId, 'plaintext');
const settingResult = vscode.workspace.getConfiguration().get<boolean>('workbench.editor.untitled.experimentalLanguageDetection');
assert.ok(settingResult);
const result = await editor.edit(editBuilder => {
editBuilder.insert(new vscode.Position(0, 0), `{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": false,
"outDir": "../out/vs",
"target": "es2020",
"types": [
"keytar",
"mocha",
"semver",
"sinon",
"winreg",
"trusted-types",
"wicg-file-system-access"
],
"plugins": [
{
"name": "tsec",
"exemptionConfig": "./tsec.exemptions.json"
}
]
},
"include": [
"./typings",
"./vs"
]
}`);
});
assert.ok(result);
// Changing the language triggers a file to be closed and opened again so wait for that event to happen.
const newDoc = await asPromise(vscode.workspace.onDidOpenTextDocument, 5000);
assert.strictEqual(newDoc.languageId, 'json');
});
});