File tree Expand file tree Collapse file tree 3 files changed +71
-2
lines changed
e2e/tolk/testcases/rename Expand file tree Collapse file tree 3 files changed +71
-2
lines changed Original file line number Diff line number Diff line change @@ -480,7 +480,6 @@ Rename builtin type
480
480
========================================================================
481
481
fun test(): int {
482
482
//! ^ bool
483
- }
484
483
}
485
484
------------------------------------------------------------------------
486
485
The element can't be renamed.
@@ -491,7 +490,40 @@ Rename stdlib function
491
490
fun test(): int {
492
491
minMax();
493
492
//! ^ otherFunc
494
- }
495
493
}
496
494
------------------------------------------------------------------------
497
495
The element can't be renamed.
496
+
497
+ ========================================================================
498
+ Wrap in backtick for keyword name
499
+ ========================================================================
500
+ fun foo() {}
501
+
502
+ fun test(): int {
503
+ foo();
504
+ //! ^ return
505
+ }
506
+ ------------------------------------------------------------------------
507
+ fun `return`() {}
508
+
509
+ fun test(): int {
510
+ `return`();
511
+ //! ^ return
512
+ }
513
+
514
+ ========================================================================
515
+ Wrap in backtick for keyword name 2
516
+ ========================================================================
517
+ fun foo() {}
518
+
519
+ fun test(): int {
520
+ foo();
521
+ //! ^ match
522
+ }
523
+ ------------------------------------------------------------------------
524
+ fun `match`() {}
525
+
526
+ fun test(): int {
527
+ `match`();
528
+ //! ^ match
529
+ }
Original file line number Diff line number Diff line change @@ -4,3 +4,38 @@ export function trimBackticks(text: string): string {
4
4
}
5
5
return text
6
6
}
7
+
8
+ export const KEYWORDS = new Set ( [
9
+ "tolk" ,
10
+ "import" ,
11
+ "global" ,
12
+ "const" ,
13
+ "type" ,
14
+ "struct" ,
15
+ "fun" ,
16
+ "get" ,
17
+ "mutate" ,
18
+ "asm" ,
19
+ "builtin" ,
20
+ "var" ,
21
+ "val" ,
22
+ "return" ,
23
+ "repeat" ,
24
+ "if" ,
25
+ "else" ,
26
+ "do" ,
27
+ "while" ,
28
+ "break" ,
29
+ "continue" ,
30
+ "throw" ,
31
+ "assert" ,
32
+ "try" ,
33
+ "catch" ,
34
+ "lazy" ,
35
+ "is" ,
36
+ "!is" ,
37
+ "match" ,
38
+ "true" ,
39
+ "false" ,
40
+ "null" ,
41
+ ] )
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import {NamedNode} from "@server/languages/tolk/psi/TolkNode"
7
7
import { Reference } from "@server/languages/tolk/psi/Reference"
8
8
import type { Node as SyntaxNode } from "web-tree-sitter"
9
9
import type { Position } from "vscode-languageclient"
10
+ import { KEYWORDS } from "@server/languages/tolk/lang/names-util"
10
11
11
12
export function provideTolkRename ( params : lsp . RenameParams , file : TolkFile ) : WorkspaceEdit | null {
12
13
const renameNode = findRenameTarget ( params , file )
@@ -82,6 +83,7 @@ export function provideTolkRenamePrepare(
82
83
}
83
84
84
85
function isValidIdentifier ( name : string ) : boolean {
86
+ if ( KEYWORDS . has ( name ) ) return false
85
87
return / ^ [ A - Z _ a - z ] \w * $ / . test ( name )
86
88
}
87
89
You can’t perform that action at this time.
0 commit comments