Skip to content

Commit

Permalink
[VSC-6] Add didChange benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
krendelhoff2 committed Feb 23, 2025
1 parent 38684d3 commit 1c7fb9e
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/server/bench/benchmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { readFileSync } from 'node:fs';
import { DocumentSymbol, Hover } from 'vscode-languageserver/node';
import { URI } from 'vscode-uri';
import { createBenchmark, Setup, wait } from './helpers';
import { join } from 'node:path';

createBenchmark('didChange', async (setup: Setup) => {
const file = join(
setup.rootUri.fsPath,
'src',
'game_launcher_backend',
'launchpad',
'swap.mo',
);
const fileUri = URI.file(file);
const document = {
uri: `${fileUri}`,
version: 1,
text: readFileSync(file, 'utf-8'),
};

await setup.sendNotification('textDocument/didOpen', {
textDocument: {
...document,
languageId: 'motoko',
},
});

await setup.sendNotification('workspace/didChangeConfiguration', {
settings: {
motoko: {
dfx: 'dfx',
legacyLanguageServer: true,
maxNumberOfProblems: 100,
hideWarningRegex: '',
trace: {
server: 'verbose',
},
debugHover: false,
canister: '',
formatter: 'prettier',
},
},
});

await setup.benchmark<DocumentSymbol>('textDocument/documentSymbol', {
textDocument: { uri: document.uri },
});

await setup.benchmark<Hover>('textDocument/hover', {
textDocument: { uri: document.uri },
position: { line: 14, character: 15 },
});

await wait(3);

await setup.benchmark<Hover>('textDocument/hover', {
textDocument: { uri: document.uri },
position: { line: 14, character: 15 },
});

document.version++;
await setup.sendNotification(
'textDocument/didChange',
{
textDocument: {
uri: document.uri,
version: document.version,
},
contentChanges: [
{
text: document.text,
},
],
},
100,
);

await wait(0.5);

await setup.benchmark<Hover>('textDocument/hover', {
textDocument: { uri: document.uri },
position: { line: 64, character: 14 },
});
});

0 comments on commit 1c7fb9e

Please sign in to comment.