Skip to content

Commit

Permalink
Fix keywords and operators being kept when parsing a parent node fails (
Browse files Browse the repository at this point in the history
#630)

Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
  • Loading branch information
jansul and Sija committed Aug 22, 2023
1 parent 8908ef4 commit 150ba48
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 3 deletions.
106 changes: 106 additions & 0 deletions spec/language_server/semantic_tokens/component
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
component Test {
property nextTitle : String = "World"

/*
Comment that spans
multiple lines
*/
fun title : String {
nextTitle
}

fun render {
<div/>
}
}
------------------------------------------------------------------file test.mint
{
"id": 0,
"method": "initialize",
"params": {
"capabilities": {
"textDocument": {
"semanticTokens": {
"dynamicRegistration": false,
"tokenTypes": ["property"]
}
}
}
}
}
-------------------------------------------------------------------------request
{
"jsonrpc": "2.0",
"id": 1,
"params": {
"textDocument": {
"uri": "file://#{root_path}/test.mint"
}
},
"method": "textDocument/semanticTokens/full"
}
-------------------------------------------------------------------------request
{
"jsonrpc": "2.0",
"result": {
"data": [
0,
0,
9,
4,
0,
0,
10,
4,
1,
0,
1,
2,
8,
4,
0,
0,
21,
6,
1,
0,
0,
9,
7,
8,
0,
2,
2,
48,
5,
0,
4,
2,
3,
4,
0,
0,
12,
6,
1,
0,
1,
4,
9,
6,
0,
3,
2,
3,
4,
0,
1,
5,
3,
2,
0
]
},
"id": 1
}
------------------------------------------------------------------------response
19 changes: 16 additions & 3 deletions src/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,29 @@ module Mint

def start(&)
start_position = position
node_size = ast.nodes.size

nodes_size = ast.nodes.size
keywords_size = ast.keywords.size
operators_size = ast.operators.size

begin
node = yield position
@position = start_position unless node
ast.nodes.delete_at(node_size...) unless node

unless node
ast.nodes.delete_at(nodes_size...)
ast.keywords.delete_at(keywords_size...)
ast.operators.delete_at(operators_size...)
end

node
rescue error : Error
@position = start_position
ast.nodes.delete_at(node_size...)

ast.nodes.delete_at(nodes_size...)
ast.keywords.delete_at(keywords_size...)
ast.operators.delete_at(operators_size...)

raise error
end
end
Expand Down

0 comments on commit 150ba48

Please sign in to comment.