-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into joh/uri-whatwg-like
- Loading branch information
Showing
76 changed files
with
1,014 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
extensions/typescript-language-features/src/test/jsDocCompletions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as assert from 'assert'; | ||
import 'mocha'; | ||
import * as vscode from 'vscode'; | ||
import { disposeAll } from '../utils/dispose'; | ||
import { createTestEditor, joinLines, wait } from './testUtils'; | ||
import { acceptFirstSuggestion } from './suggestTestHelpers'; | ||
|
||
const testDocumentUri = vscode.Uri.parse('untitled:test.ts'); | ||
|
||
suite('JSDoc Completions', () => { | ||
const _disposables: vscode.Disposable[] = []; | ||
|
||
setup(async () => { | ||
await wait(100); | ||
}); | ||
|
||
teardown(async () => { | ||
disposeAll(_disposables); | ||
}); | ||
|
||
test('Should complete jsdoc inside single line comment', async () => { | ||
await createTestEditor(testDocumentUri, | ||
`/**$0 */`, | ||
`function abcdef(x, y) { }`, | ||
); | ||
|
||
const document = await acceptFirstSuggestion(testDocumentUri, _disposables, { useLineRange: true}); | ||
assert.strictEqual( | ||
document.getText(), | ||
joinLines( | ||
`/**`, | ||
` *`, | ||
` * @param {*} x `, | ||
` * @param {*} y `, | ||
` */`, | ||
`function abcdef(x, y) { }`, | ||
)); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
extensions/typescript-language-features/src/test/suggestTestHelpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import 'mocha'; | ||
import * as vscode from 'vscode'; | ||
import { wait } from './testUtils'; | ||
|
||
export async function acceptFirstSuggestion(uri: vscode.Uri, _disposables: vscode.Disposable[], options?: { useLineRange?: boolean }) { | ||
const didChangeDocument = onChangedDocument(uri, _disposables); | ||
const didSuggest = onDidSuggest(_disposables, options); | ||
await vscode.commands.executeCommand('editor.action.triggerSuggest'); | ||
await didSuggest; | ||
// TODO: depends on reverting fix for https://github.com/Microsoft/vscode/issues/64257 | ||
// Make sure we have time to resolve the suggestion because `acceptSelectedSuggestion` doesn't | ||
await wait(40); | ||
await vscode.commands.executeCommand('acceptSelectedSuggestion'); | ||
return await didChangeDocument; | ||
} | ||
|
||
export async function typeCommitCharacter(uri: vscode.Uri, character: string, _disposables: vscode.Disposable[]) { | ||
const didChangeDocument = onChangedDocument(uri, _disposables); | ||
const didSuggest = onDidSuggest(_disposables); | ||
await vscode.commands.executeCommand('editor.action.triggerSuggest'); | ||
await didSuggest; | ||
await vscode.commands.executeCommand('type', { text: character }); | ||
return await didChangeDocument; | ||
} | ||
|
||
export function onChangedDocument(documentUri: vscode.Uri, disposables: vscode.Disposable[]) { | ||
return new Promise<vscode.TextDocument>(resolve => vscode.workspace.onDidChangeTextDocument(e => { | ||
if (e.document.uri.toString() === documentUri.toString()) { | ||
resolve(e.document); | ||
} | ||
}, undefined, disposables)); | ||
} | ||
|
||
|
||
function onDidSuggest(disposables: vscode.Disposable[], options?: { useLineRange?: boolean }) { | ||
return new Promise(resolve => | ||
disposables.push(vscode.languages.registerCompletionItemProvider('typescript', new class implements vscode.CompletionItemProvider { | ||
provideCompletionItems(doc: vscode.TextDocument, position: vscode.Position): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> { | ||
// Return a fake item that will come first | ||
const range = options && options.useLineRange | ||
? new vscode.Range(new vscode.Position(position.line, 0), position) | ||
: doc.getWordRangeAtPosition(position.translate({ characterDelta: -1 })); | ||
return [{ | ||
label: '🦄', | ||
insertText: doc.getText(range), | ||
filterText: doc.getText(range), | ||
preselect: true, | ||
sortText: 'a', | ||
range: range | ||
}]; | ||
} | ||
async resolveCompletionItem(item: vscode.CompletionItem) { | ||
await vscode.commands.executeCommand('selectNextSuggestion'); | ||
resolve(); | ||
return item; | ||
} | ||
}))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.