@@ -2758,7 +2758,7 @@ func (b *Binder) errorOrSuggestionOnRange(isError bool, startNode *ast.Node, end
2758
2758
// If so, the node _must_ be in the current file (as that's the only way anything could have traversed to it to yield it as the error node)
2759
2759
// This version of `createDiagnosticForNode` uses the binder's context to account for this, and always yields correct diagnostics even in these situations.
2760
2760
func (b * Binder ) createDiagnosticForNode (node * ast.Node , message * diagnostics.Message , args ... any ) * ast.Diagnostic {
2761
- return ast .NewDiagnostic (b .file , GetErrorRangeForNode (b .file , node ), message , args ... )
2761
+ return ast .NewDiagnostic (b .file , scanner . GetErrorRangeForNode (b .file , node ), message , args ... )
2762
2762
}
2763
2763
2764
2764
func (b * Binder ) addDiagnostic (diagnostic * ast.Diagnostic ) {
@@ -2855,83 +2855,3 @@ func isAssignmentDeclaration(decl *ast.Node) bool {
2855
2855
func isEffectiveModuleDeclaration (node * ast.Node ) bool {
2856
2856
return ast .IsModuleDeclaration (node ) || ast .IsIdentifier (node )
2857
2857
}
2858
-
2859
- func getErrorRangeForArrowFunction (sourceFile * ast.SourceFile , node * ast.Node ) core.TextRange {
2860
- pos := scanner .SkipTrivia (sourceFile .Text (), node .Pos ())
2861
- body := node .AsArrowFunction ().Body
2862
- if body != nil && body .Kind == ast .KindBlock {
2863
- startLine , _ := scanner .GetLineAndCharacterOfPosition (sourceFile , body .Pos ())
2864
- endLine , _ := scanner .GetLineAndCharacterOfPosition (sourceFile , body .End ())
2865
- if startLine < endLine {
2866
- // The arrow function spans multiple lines,
2867
- // make the error span be the first line, inclusive.
2868
- return core .NewTextRange (pos , scanner .GetEndLinePosition (sourceFile , startLine ))
2869
- }
2870
- }
2871
- return core .NewTextRange (pos , node .End ())
2872
- }
2873
-
2874
- func GetErrorRangeForNode (sourceFile * ast.SourceFile , node * ast.Node ) core.TextRange {
2875
- errorNode := node
2876
- switch node .Kind {
2877
- case ast .KindSourceFile :
2878
- pos := scanner .SkipTrivia (sourceFile .Text (), 0 )
2879
- if pos == len (sourceFile .Text ()) {
2880
- return core .NewTextRange (0 , 0 )
2881
- }
2882
- return scanner .GetRangeOfTokenAtPosition (sourceFile , pos )
2883
- // This list is a work in progress. Add missing node kinds to improve their error spans
2884
- case ast .KindFunctionDeclaration , ast .KindMethodDeclaration :
2885
- if node .Flags & ast .NodeFlagsReparsed != 0 {
2886
- errorNode = node
2887
- break
2888
- }
2889
- fallthrough
2890
- case ast .KindVariableDeclaration , ast .KindBindingElement , ast .KindClassDeclaration , ast .KindClassExpression , ast .KindInterfaceDeclaration ,
2891
- ast .KindModuleDeclaration , ast .KindEnumDeclaration , ast .KindEnumMember , ast .KindFunctionExpression ,
2892
- ast .KindGetAccessor , ast .KindSetAccessor , ast .KindTypeAliasDeclaration , ast .KindJSTypeAliasDeclaration , ast .KindPropertyDeclaration ,
2893
- ast .KindPropertySignature , ast .KindNamespaceImport :
2894
- errorNode = ast .GetNameOfDeclaration (node )
2895
- case ast .KindArrowFunction :
2896
- return getErrorRangeForArrowFunction (sourceFile , node )
2897
- case ast .KindCaseClause , ast .KindDefaultClause :
2898
- start := scanner .SkipTrivia (sourceFile .Text (), node .Pos ())
2899
- end := node .End ()
2900
- statements := node .AsCaseOrDefaultClause ().Statements .Nodes
2901
- if len (statements ) != 0 {
2902
- end = statements [0 ].Pos ()
2903
- }
2904
- return core .NewTextRange (start , end )
2905
- case ast .KindReturnStatement , ast .KindYieldExpression :
2906
- pos := scanner .SkipTrivia (sourceFile .Text (), node .Pos ())
2907
- return scanner .GetRangeOfTokenAtPosition (sourceFile , pos )
2908
- case ast .KindSatisfiesExpression :
2909
- pos := scanner .SkipTrivia (sourceFile .Text (), node .AsSatisfiesExpression ().Expression .End ())
2910
- return scanner .GetRangeOfTokenAtPosition (sourceFile , pos )
2911
- case ast .KindConstructor :
2912
- if node .Flags & ast .NodeFlagsReparsed != 0 {
2913
- errorNode = node
2914
- break
2915
- }
2916
- scanner := scanner .GetScannerForSourceFile (sourceFile , node .Pos ())
2917
- start := scanner .TokenStart ()
2918
- for scanner .Token () != ast .KindConstructorKeyword && scanner .Token () != ast .KindStringLiteral && scanner .Token () != ast .KindEndOfFile {
2919
- scanner .Scan ()
2920
- }
2921
- return core .NewTextRange (start , scanner .TokenEnd ())
2922
- // !!!
2923
- // case KindJSDocSatisfiesTag:
2924
- // pos := scanner.SkipTrivia(sourceFile.Text(), node.tagName.pos)
2925
- // return scanner.GetRangeOfTokenAtPosition(sourceFile, pos)
2926
- }
2927
- if errorNode == nil {
2928
- // If we don't have a better node, then just set the error on the first token of
2929
- // construct.
2930
- return scanner .GetRangeOfTokenAtPosition (sourceFile , node .Pos ())
2931
- }
2932
- pos := errorNode .Pos ()
2933
- if ! ast .NodeIsMissing (errorNode ) && ! ast .IsJsxText (errorNode ) {
2934
- pos = scanner .SkipTrivia (sourceFile .Text (), pos )
2935
- }
2936
- return core .NewTextRange (pos , errorNode .End ())
2937
- }
0 commit comments