rbasniak
rbasniak

Reputation: 4964

VS Code API get position of closing parenthesis

I tried to look over the API reference but didn't find anything, but since this is my first attempt on creating an extension I decided to try to ask here: is there any API that given an open parenthesis position it gives me the position ot the matching closing parenthesis?

Upvotes: 0

Views: 315

Answers (1)

Scott McPeak
Scott McPeak

Reputation: 12749

Parenthesis (bracket) matching is implemented in textModel.ts, function _matchBracket. It is exposed by bracketMatching.ts, which publishes commands editor.action.jumpToBracket and editor.action.selectToBracket that you can invoke using executeCommand. It does not publish any way to query the bracket info without changing the selections.

VSCode Issue #7177: Expose bracket matching functionality to extensions asked for a query-only capability. It was closed in November 2017 because it "will not be considered in the next 6-12 months".

So, if you want to query the matching bracket for an arbitrary position without changing any editor state, I think you have to save the current selections, move the cursor to the position of interest, invoke jumpToBracket, record where the cursor went, then restore the selections.

Upvotes: 2

Related Questions