forked from vshaxe/haxe-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
240 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/haxeLanguageServer/features/haxe/codeAction/TokenTreeUtils.hx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package haxeLanguageServer.features.haxe.codeAction; | ||
|
||
import tokentree.TokenTree; | ||
|
||
class TokenTreeUtils { | ||
public static function isInFunctionScope(token:TokenTree):Bool { | ||
final brOpen = token.parent ?? return false; | ||
if (brOpen.tok != BrOpen) | ||
return false; | ||
final name = brOpen.parent ?? return false; | ||
// `function() {}` or `() -> {}` | ||
if (name.tok.match(Kwd(KwdFunction) | Arrow)) | ||
return true; | ||
final fun = name.parent ?? return false; | ||
// `function name() {}` | ||
return fun.tok.match(Kwd(KwdFunction)); | ||
} | ||
|
||
public static function isInLoopScope(token:TokenTree):Bool { | ||
var kwd = token.parent ?? return false; | ||
if (kwd.tok == BrOpen) | ||
kwd = kwd.parent ?? return false; | ||
return kwd.tok.match(Kwd(KwdFor | KwdDo | KwdWhile)); | ||
} | ||
|
||
public static function isAnonStructure(brToken:TokenTree):Bool { | ||
if (brToken.tok == BrClose) | ||
brToken = brToken.parent ?? return false; | ||
final first = brToken!.getFirstChild() ?? return false; | ||
final colon = first.getFirstChild() ?? return false; | ||
if (colon.tok.match(DblDot) && !colon.nextSibling!.tok.match(Semicolon)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public static function isAnonStructureField(token:TokenTree):Bool { | ||
final parent = token.parent ?? return false; | ||
if (!isAnonStructure(parent)) | ||
return false; | ||
final colon = token.getFirstChild() ?? return false; | ||
return colon.tok.match(DblDot); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters