forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For microsoft/TypeScript#51832 Not actually implemented on TS yet
- Loading branch information
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
extensions/typescript-language-features/src/languageFeatures/jsxLinkedEditing.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,49 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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 { ClientCapability, ITypeScriptServiceClient } from '../typescriptService'; | ||
import { conditionalRegistration, requireMinVersion, requireSomeCapability } from '../utils/dependentRegistration'; | ||
import { DocumentSelector } from '../utils/documentSelector'; | ||
import * as typeConverters from '../utils/typeConverters'; | ||
import API from '../utils/api'; | ||
|
||
class JsxLinkedEditingSupport implements vscode.LinkedEditingRangeProvider { | ||
|
||
public static readonly minVersion = API.v510; | ||
|
||
public constructor( | ||
private readonly client: ITypeScriptServiceClient | ||
) { } | ||
|
||
async provideLinkedEditingRanges(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.LinkedEditingRanges | undefined> { | ||
const filepath = this.client.toOpenTsFilePath(document); | ||
if (!filepath) { | ||
return undefined; | ||
} | ||
|
||
const args = typeConverters.Position.toFileLocationRequestArgs(filepath, position); | ||
const response = await this.client.execute('jsxLinkedTag', args, token); | ||
if (response.type !== 'response' || !response.body) { | ||
return undefined; | ||
} | ||
|
||
const wordPattern = response.body.wordPattern ? new RegExp(response.body.wordPattern) : undefined; | ||
return new vscode.LinkedEditingRanges(response.body.ranges.map(range => typeConverters.Range.fromTextSpan(range)), wordPattern); | ||
} | ||
} | ||
|
||
export function register( | ||
selector: DocumentSelector, | ||
client: ITypeScriptServiceClient | ||
) { | ||
return conditionalRegistration([ | ||
requireMinVersion(client, JsxLinkedEditingSupport.minVersion), | ||
requireSomeCapability(client, ClientCapability.Syntax), | ||
], () => { | ||
return vscode.languages.registerLinkedEditingRangeProvider(selector.semantic, | ||
new JsxLinkedEditingSupport(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
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