File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
66The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
77and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
88
9+ ## [ Unreleased]
10+
11+ ### Fixed
12+
13+ - Escape character inserted before ` } ` when applying code action
14+ with ` SnippetTextEdit ` [[ #303 ] ( https://github.com/mrcjkb/rustaceanvim/issues/303 )] .
15+
916## [ 4.18.2] - 2024-03-28
1017
1118### Changed
Original file line number Diff line number Diff line change 11local M = {}
22
3+ --- @param input string unparsed snippet
4+ --- @return string parsed snippet
5+ local function parse_snippet_fallback (input )
6+ local output = input
7+ -- $0 -> Nothing
8+ :gsub (' %$%d' , ' ' )
9+ -- ${0:_} -> _
10+ :gsub (' %${%d:(.-)}' , ' %1' )
11+ :gsub ([[ \}]] , ' }' )
12+ return output
13+ end
14+
15+ --- @param input string unparsed snippet
16+ --- @return string parsed snippet
17+ local function parse_snippet (input )
18+ local ok , parsed = pcall (function ()
19+ return vim .lsp ._snippet_grammar .parse (input )
20+ end )
21+ return ok and tostring (parsed ) or parse_snippet_fallback (input )
22+ end
23+
324--- @param spe ? table
425function M .snippet_text_edits_to_text_edits (spe )
526 if type (spe ) ~= ' table' then
627 return
728 end
829 for _ , value in ipairs (spe ) do
930 if value .newText and value .insertTextFormat then
10- -- $0 -> Nothing
11- value .newText = string.gsub (value .newText , ' %$%d' , ' ' )
12- -- ${0:_} -> _
13- value .newText = string.gsub (value .newText , ' %${%d:(.-)}' , ' %1' )
31+ value .newText = parse_snippet (value .newText )
1432 end
1533 end
1634end
You can’t perform that action at this time.
0 commit comments