Skip to content

WIP Porting more completion tests and adding text change methods #8311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions src/razor/src/document/razorDocumentSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,26 @@ export class RazorDocumentSynchronizer {
token: vscode.CancellationToken
) {
const rejectionsForCancel: Array<(reason: string) => void> = [];
function isTokenCancellationRequestedError(err: unknown): boolean {
return typeof err === 'string' && err === 'Token cancellation requested: {0}';
}
let projectedDocumentSynchronized: () => void = Function;
const onProjectedDocumentSynchronized = new Promise<void>((resolve, reject) => {
projectedDocumentSynchronized = resolve;
rejectionsForCancel.push(reject);
}).catch((err) => {
if (!isTokenCancellationRequestedError(err)) {
throw err;
}
});
let projectedTextDocumentSynchronized: () => void = Function;
const onProjectedTextDocumentSynchronized = new Promise<void>((resolve, reject) => {
projectedTextDocumentSynchronized = resolve;
rejectionsForCancel.push(reject);
}).catch((err) => {
if (!isTokenCancellationRequestedError(err)) {
throw err;
}
});

token.onCancellationRequested((reason) => {
Expand Down
114 changes: 113 additions & 1 deletion test/razor/razorIntegrationTests/completion.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ integrationHelpers.describeIfDevKit(`Razor Hover ${testAssetWorkspace.descriptio
vscode.CompletionItemKind.TypeParameter,
'text'
);

await clearLine(4);
});

test('Div Tag', async () => {
Expand All @@ -65,8 +67,112 @@ integrationHelpers.describeIfDevKit(`Razor Hover ${testAssetWorkspace.descriptio
'div',
expectedDocumentation
);

await clearLine(6);
}, 30000);

test('Disabled Attribute', async () => {
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
return;
}

await insertText(new vscode.Position(6, 0), '<button dis');

await waitForExpectedCompletionItemAsync(
new vscode.Position(6, 11),
undefined,
undefined,
'disabled',
vscode.CompletionItemKind.Value,
'disabled'
);

await clearLine(6);
}, 30000);

test('Dir Attribute', async () => {
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
return;
}

await insertText(new vscode.Position(6, 0), '<div dir=');

await waitForExpectedCompletionItemAsync(
new vscode.Position(6, 9),
undefined,
undefined,
'auto',
vscode.CompletionItemKind.Unit,
'"auto"'
);

await clearLine(6);
}, 30000);

test('C# String Type', async () => {
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
return;
}

await insertText(new vscode.Position(8, 0), 'str');

await waitForExpectedCompletionItemAsync(
new vscode.Position(8, 3),
undefined,
undefined,
'string',
vscode.CompletionItemKind.Keyword,
'string'
);

await clearLine(8);
}, 30000);

test('C# Override', async () => {
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
return;
}

await insertText(new vscode.Position(8, 0), 'override OnA');

await waitForExpectedCompletionItemAsync(
new vscode.Position(8, 12),
undefined,
undefined,
'OnAfterRender(bool firstRender)',
vscode.CompletionItemKind.Method,
// This is not correct - filed https://github.com/dotnet/vscode-csharp/issues/8310
'OnA'
);

await clearLine(8);
}, 30000);

async function insertText(position: vscode.Position, text: string): Promise<void> {
const activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
throw new Error('No active editor');
}

await activeEditor.edit((builder) => {
builder.insert(position, text);
});
}

async function clearLine(lineNumber: number): Promise<void> {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}

const lineObj = editor.document.lineAt(lineNumber);
const textRange = new vscode.Range(lineObj.range.start, lineObj.range.end);

await editor.edit((editBuilder) => {
editBuilder.delete(textRange);
});
}

async function getCompletionsAsync(
position: vscode.Position,
triggerCharacter: string | undefined,
Expand Down Expand Up @@ -117,7 +223,13 @@ integrationHelpers.describeIfDevKit(`Razor Hover ${testAssetWorkspace.descriptio
}
expect(completionItem).toBeDefined();
expect(completionItem!.kind).toEqual(expectedKind);
expect(completionItem!.insertText).toBe(expectedInsertText);

const insertText =
completionItem.insertText instanceof vscode.SnippetString
? completionItem.insertText.value
: completionItem.insertText;
expect(insertText).toBe(expectedInsertText);

if (expectedDocumentation) {
const documentation = completionItem!.documentation as vscode.MarkdownString;
expect(documentation.value).toBe(expectedDocumentation);
Expand Down
Loading