Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/inlineEdits/test/vscode-node/naturalLanguageHint.test.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as assert from 'assert';
7
import * as vscode from 'vscode';
8
import { LineCheck } from '../../vscode-node/naturalLanguageHint';
9
10
suite('LineCheck.isMostlyNaturalLanguage', () => {
11
12
async function createMockDocument(lines: string[], languageId: string = 'typescript'): Promise<vscode.TextDocument> {
13
return await vscode.workspace.openTextDocument({ language: languageId, content: lines.join('\n') });
14
}
15
16
test('should return false for lines with too little content', async () => {
17
const document = await createMockDocument(['']);
18
const position = new vscode.Position(0, 0);
19
const result = LineCheck.isNaturalLanguageDominated(document, position);
20
assert.strictEqual(result, false);
21
});
22
23
test('should return true for lines with mostly natural language including interface', async () => {
24
const document = await createMockDocument(['interface Car with make, age and mileage']);
25
const position = new vscode.Position(0, 39);
26
const result = LineCheck.isNaturalLanguageDominated(document, position);
27
assert.strictEqual(result, true);
28
});
29
30
test('should return false for lines with function declaration', async () => {
31
const document = await createMockDocument(['function foo(a:number, b:string) {', ' console.log the args here}']);
32
const position = new vscode.Position(1, 25);
33
const result = LineCheck.isNaturalLanguageDominated(document, position);
34
assert.strictEqual(result, true);
35
});
36
test('should return false for lines with too many keywords', async () => {
37
const document = await createMockDocument(['const let var function']);
38
const position = new vscode.Position(0, 21);
39
const result = LineCheck.isNaturalLanguageDominated(document, position);
40
assert.strictEqual(result, false);
41
});
42
43
test('should return false for lines with too much punctuation', async () => {
44
const document = await createMockDocument(['word1, word2; word3.']);
45
const position = new vscode.Position(0, 19);
46
const result = LineCheck.isNaturalLanguageDominated(document, position);
47
assert.strictEqual(result, false);
48
});
49
50
test('should return true for lines with mostly natural language', async () => {
51
const document = await createMockDocument(['This is a test sentence with words.']);
52
const position = new vscode.Position(0, 34);
53
const result = LineCheck.isNaturalLanguageDominated(document, position);
54
assert.strictEqual(result, true);
55
});
56
57
test('should return false for lines with less than 4 tokens', async () => {
58
const document = await createMockDocument(['word1 word2']);
59
const position = new vscode.Position(0, 10);
60
const result = LineCheck.isNaturalLanguageDominated(document, position);
61
assert.strictEqual(result, false);
62
});
63
64
test('should return false for lines with less than 2 spaces', async () => {
65
const document = await createMockDocument(['word1,word2,word3']);
66
const position = new vscode.Position(0, 16);
67
const result = LineCheck.isNaturalLanguageDominated(document, position);
68
assert.strictEqual(result, false);
69
});
70
71
test('should return false for lines with class declaration', async () => {
72
const document = await createMockDocument(['class AbstractPaneCompositeBar extends Disposable']);
73
const position = new vscode.Position(0, 49);
74
const result = LineCheck.isNaturalLanguageDominated(document, position);
75
assert.strictEqual(result, false);
76
});
77
78
test('Example of inline <tab> heuristic being too eager #8151', async () => {
79
const document = await createMockDocument([' const usedCacheEntries = await coll']);
80
const position = new vscode.Position(0, 36);
81
const result = LineCheck.isNaturalLanguageDominated(document, position);
82
assert.strictEqual(result, false);
83
});
84
85
test('Eager inline chat hints #8240m, part 1', async () => {
86
const document = await createMockDocument(['return new SD']);
87
const position = new vscode.Position(0, 13);
88
const result = LineCheck.isNaturalLanguageDominated(document, position);
89
assert.strictEqual(result, false);
90
});
91
92
test('Eager inline chat hints #8240, part 2', async () => {
93
const document = await createMockDocument([
94
'export class SummarizedDocumentInput {',
95
'',
96
' static async create(): SummarizedDocumentInput',
97
' ',
98
' }',
99
'}'
100
]);
101
const position = new vscode.Position(2, 47);
102
const result = LineCheck.isNaturalLanguageDominated(document, position);
103
assert.strictEqual(result, false);
104
});
105
106
107
test('Eager inline chat hints #8240m, part 3', async () => {
108
const document = await createMockDocument(['(token as Token).']);
109
const position = new vscode.Position(0, 17);
110
const result = LineCheck.isNaturalLanguageDominated(document, position);
111
assert.strictEqual(result, false);
112
});
113
114
test('Inline hint trigger and keyword prefixes #10198', async () => {
115
const document = await createMockDocument(['class FooBarBazzFactory implemen']);
116
const position = new vscode.Position(0, 32);
117
const result = LineCheck.isNaturalLanguageDominated(document, position);
118
assert.strictEqual(result, false);
119
});
120
121
test('Haskell', async () => {
122
const document = await createMockDocument(['reverse xs'], 'haskell');
123
const position = new vscode.Position(0, 10);
124
const result = LineCheck.isNaturalLanguageDominated(document, position);
125
assert.strictEqual(result, false);
126
});
127
128
test('Haskell (trailing space)', async () => {
129
const document = await createMockDocument(['reverse xs '], 'haskell');
130
const position = new vscode.Position(0, 11);
131
const result = LineCheck.isNaturalLanguageDominated(document, position);
132
assert.strictEqual(result, false);
133
});
134
135
test('Haskell 2', async () => {
136
const document = await createMockDocument(['sumfn a b'], 'haskell');
137
const position = new vscode.Position(0, 10);
138
const result = LineCheck.isNaturalLanguageDominated(document, position);
139
assert.strictEqual(result, false);
140
});
141
142
test('https://github.com/microsoft/vscode-copilot/issues/11370', async () => {
143
const document = await createMockDocument([
144
'<h2 class="subtitle"›',
145
'Thanks for visiting our fun and colorful project! We hope you enjoyed your stay.',
146
'i am a new line',
147
'</h2>'], 'html');
148
const position = new vscode.Position(2, 15);
149
const result = LineCheck.isNaturalLanguageDominated(document, position);
150
assert.strictEqual(result, false);
151
});
152
});
153
154