Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix unit tests
  • Loading branch information
rchiodo committed Sep 21, 2020
commit 92e5b9431e57d09fde7ed38697c88d5f0f2cfe74
26 changes: 21 additions & 5 deletions src/test/datascience/mockLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export class MockLanguageServer implements ILanguageServer {
}

public get capabilities() {
return {};
return {
textDocumentSync: 2 // This is increment value. Means we support changes
} as any;
}

public provideRenameEdits(
Expand Down Expand Up @@ -137,8 +139,10 @@ export class MockLanguageServer implements ILanguageServer {
noop();
}

private sendNotification(method: string, params: any): void {
if (method === vscodeLanguageClient.DidChangeTextDocumentNotification.type.method) {
private sendNotification(method: any, params: any): void {
if (method === vscodeLanguageClient.DidChangeTextDocumentNotification.type) {
const doc = params.textDocument;
this.versionId = doc.version;
const changes = params.contentChanges;
this.applyChanges(changes);
this.resolveNotificationPromise();
Expand All @@ -147,13 +151,25 @@ export class MockLanguageServer implements ILanguageServer {

private applyChanges(changes: TextDocumentContentChangeEvent[]) {
changes.forEach((c) => {
const before = this.contents.substr(0, c.rangeOffset);
const after = this.contents.substr(c.rangeOffset + c.rangeLength);
const offset = this.computeOffset(c);
const before = this.contents.substr(0, offset);
const after = this.contents.substr(offset + c.rangeLength);
this.contents = `${before}${c.text}${after}`;
});
this.versionId = this.versionId + 1;
}

private computeOffset(c: TextDocumentContentChangeEvent): number {
// range offset is no longer available. Have to compute it using the contents
const lines = this.contents.splitLines({ trim: false, removeEmptyEntries: false });
let offset = 0;
for (let i = 0; i < c.range.start.line; i += 1) {
offset += lines[i].length + 1; // + 1 for the linefeed
}
offset += c.range.start.character;
return offset;
}

private resolveNotificationPromise() {
if (this.notificationPromise) {
this.notificationPromise.resolve();
Expand Down