Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script lang="ts">
function aFunction(param: string) {
param += 1; // should error
const foo = subFunction();

function subFunction() {
return param ? 1 : 2;
}
}

function action(node: HTMLElement) {
aFunction(true); // should error
const foo = 'bar';
}
</script>

<div use:action>
<p>lorem ipsum</p>
<slot />
</div>

<NonExistentComponent
propA={1}
on:event={(evt) => {
const result = evt.detail ? aFunction(false) : aFunction('right');
result;
}}
>
<p>Inner Content</p>
</NonExistentComponent>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as path from 'path';
import { performance } from 'perf_hooks';
import ts from 'typescript';
import { Position, Range } from 'vscode-languageserver';
import { Document, DocumentManager } from '../../../src/lib/documents';
import { LSConfigManager } from '../../../src/ls-config';
import { TypeScriptPlugin } from '../../../src/plugins';
import { pathToUrl } from '../../../src/utils';

describe('TypeScript Plugin Performance Tests', () => {
function setup(filename: string) {
const docManager = new DocumentManager(() => document);
const testDir = path.join(__dirname, 'testfiles');
const filePath = path.join(testDir, filename);
const uri = pathToUrl(filePath);
const document = new Document(uri, ts.sys.readFile(filePath) || '');
const pluginManager = new LSConfigManager();
const plugin = new TypeScriptPlugin(docManager, pluginManager, [pathToUrl(testDir)]);
docManager.openDocument({ uri, text: document.getText() });
const updateDocument = (newText: string) =>
docManager.updateDocument({ uri, version: 1 }, [
{ range: Range.create(Position.create(9, 0), Position.create(9, 0)), text: newText }
]);
return { plugin, document, updateDocument };
}

it('should be fast enough', async () => {
const { document, plugin, updateDocument } = setup('performance');

const start = performance.now();
for (let i = 0; i < 1000; i++) {
await plugin.doHover(document, Position.create(1, 15));
await plugin.getDiagnostics(document);
await plugin.findReferences(document, Position.create(1, 15), {
includeDeclaration: true
});
await plugin.getDocumentSymbols(document);
await plugin.getSemanticTokens(document);
await plugin.prepareRename(document, Position.create(1, 15));
updateDocument('function asd() {}\n');
}
const end = performance.now();

console.log(`Performance test took ${end - start}ms`);
}).timeout(10000);
});