-
Notifications
You must be signed in to change notification settings - Fork 29.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check in stubbed out smart select support for js/ts
For microsoft/TypeScript#29071 This require upstream TS support. Check in experimental support so that TS team can test the ux of this feature
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
extensions/typescript-language-features/src/features/smartSelect.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,57 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import * as Proto from '../protocol'; | ||
import { ITypeScriptServiceClient } from '../typescriptService'; | ||
import API from '../utils/api'; | ||
import { VersionDependentRegistration } from '../utils/dependentRegistration'; | ||
import * as typeConverters from '../utils/typeConverters'; | ||
|
||
class SmartSelection implements vscode.SelectionRangeProvider { | ||
public static readonly minVersion = API.v350; | ||
|
||
public constructor( | ||
private readonly client: ITypeScriptServiceClient | ||
) { } | ||
|
||
public async provideSelectionRanges( | ||
document: vscode.TextDocument, | ||
positions: vscode.Position[], | ||
token: vscode.CancellationToken, | ||
): Promise<vscode.SelectionRange[] | undefined> { | ||
const file = this.client.toOpenedFilePath(document); | ||
if (!file) { | ||
return undefined; | ||
} | ||
|
||
const args: Proto.FileRequestArgs & { locations: Proto.Location[] } = { | ||
file, | ||
locations: positions.map(typeConverters.Position.toLocation) | ||
}; | ||
const response = await this.client.execute('selectionRange', args, token); | ||
if (response.type !== 'response' || !response.body) { | ||
return undefined; | ||
} | ||
return response.body.map(SmartSelection.convertSelectionRange); | ||
} | ||
|
||
private static convertSelectionRange( | ||
selectionRange: Proto.SelectionRange | ||
): vscode.SelectionRange { | ||
return new vscode.SelectionRange( | ||
typeConverters.Range.fromTextSpan(selectionRange.textSpan), | ||
selectionRange.parent ? SmartSelection.convertSelectionRange(selectionRange.parent) : undefined, | ||
); | ||
} | ||
} | ||
|
||
export function register( | ||
selector: vscode.DocumentSelector, | ||
client: ITypeScriptServiceClient, | ||
) { | ||
return new VersionDependentRegistration(client, SmartSelection.minVersion, () => | ||
vscode.languages.registerSelectionRangeProvider(selector, new SmartSelection(client))); | ||
} |
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