-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Mirror Cursor for JSX #51832
Comments
@octref Finally, amazing news! |
@octref Can you please share a link to the code that implements this feature for html? |
The client side implementation is more complicated: https://github.com/microsoft/vscode/blob/master/extensions/html-language-features/client/src/mirrorCursor.ts The server side is pretty easy, just need to compute mirror position: https://github.com/microsoft/vscode-html-languageservice/blob/master/src/services/htmlMatchingTagPosition.ts |
I would like to suggest an option for the languages that this feature can apply to. I work with XSL file and there is no mirror cursor. I could change the language to HTML, but I would loose formatting, highlighting, etc.. for XSL. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Isn't this technically already solved via the "Emmet: Update Tag" command? Although it doesn't work perfectly: microsoft/vscode#99896 |
The XSLT/XPath VSCode extension has built in tag-renaming (without a mirror cursor), code formatting, syntax- highlighting, outline etc. |
So it seems like the support is already available for highlighting the appropriate tag in JSX, and has been fixed at least once: microsoft/vscode#65921 I would assume that some of the same logic can be leveraged to handle renaming the tag as well, unless I'm missing something? It's late, and I'll try to look at this tomorrow but wanted to comment and bring it up before it slipped my mind. UPDATE: |
Would very much like this feature! |
Note: this feature had been renamed a thousand times and it's now called "linked editing"
@robole You need to file a feature request to Vue extension.
The API is stable but extensions still need to implement it for each language. Some tips for anyone who want to give it a try: Linked editing is now a part of Language Server Protocol (https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_linkedEditingRange), HTML extension now implements it in this way: However we all know that TypeScript extension doesn't use Language Server Protocol, so it still needs to be implemented "manually", by calling Code Extension API (in microsoft/vscode#109923) directly. I don't know whether TypeScript server protocol supports finding open/close JSX tags, but at least it's not same as document highlight. Document highlight doesn't care about type of current selected node. I may try to implement it if changes to TypeScript server is not required. Otherwise it will be a massive change, requiring coordination between Code and TypeScript teams, and pretty hard for outside contributors. |
@yume-chan There is an open feature request in Vetur (Vue extension) from Nov 2017. Pine (octref) who opened this issue is also the author of Vetur. He has it open for PR / bug bounty / sponsorship. |
I find that most of the times that I want to accomplish this: just putting the cursor in the first tag and hitting Command+D hotkey twice does what I want. As the docs say "⌘D selects the word at the cursor, or the next occurrence of the current selection." (Source) This is not perfect, however, so I absolutely would love this feature to be implemented for JSX / TSX files. |
Here's a proposal for the TS Server protocol to implement this in VS Code. TS Server protocolAdd a new request interface LinkedEditingRanges {
ranges: TextSpan[];
wordPattern?: string; // Regexp. See https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vscode-dts/vscode.d.ts#L5568
}
interface JsLinkedTagRequest extends FileLocationRequest {
command: 'jsxLinkedTag';
arguments: FileLocationRequestArgs;
}
interface JsLinkedTagResponse extends Response {
readonly body: LinkedEditingRanges;
} A few details on the expected behavior:
This same request should also let us support making normal rename (F2) rename matched tags instead of ExamplesIn these examples, const jsx = (
<div|>
</div>
); Same for cursor being anywhere on
const jsx = (
<div| style={{ color: 'red' }}>
<p>
<img />
</p>
</div>
);
const jsx = (
<div>
<p>
<img| />
</p>
</div>
);
Namespace const jsx = (
<someNamespa|ce.Thing>
</someNamespace.Thing>
); This applies for the cursor being anywhere in the tag name
Invalid tags 1 const jsx = (
<div|>
<div>
</div>
); Match what HTML does:
Invalid tags 2 const jsx = (
<div>
<div|>
</div>
); Match what HTML does:
Fragment shorthand const jsx = (
<|>
<img />
</>
); Return empty ranges (need to confirm VS Code supports this):
Only exact matches of the entire name are supported const A = thing;
const B = thing;
const jsx = (
<A>
</B>
);
|
This comment was marked as spam.
This comment was marked as spam.
For microsoft/TypeScript#51832 Not actually implemented on TS yet
@iisaduan I've updated the proposed protocol to more closely match VS Code / LSP. Here's the LSP linked editing spec for reference: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_linkedEditingRange This PR against VS Code also stubs out this feature using the proposed API: microsoft/vscode#176279 Let me know once you have something on the TS side and I will update the VS Code PR to match the actual protocol |
For microsoft/TypeScript#51832 Not actually implemented on TS yet
* Add stubs jsx linked editing For microsoft/TypeScript#51832 * Update for new TS changes * Update to finalized protocol
I see this issue is closed, but it still doesn't work for me. Is JSX linked editing supported? |
@Cristy94 be sure that |
Am I missing anything? Is there a shortcut for it? I didn't find any documentation for this feature. |
microsoft/vscode#47069 implements this for HTML.
We should look for a way to support this for JSX/TSX.
The text was updated successfully, but these errors were encountered: