(l *LanguageService, sourceFile *ast.SourceFile, pos int)
| 29 | } |
| 30 | |
| 31 | func getSmartSelectionRange(l *LanguageService, sourceFile *ast.SourceFile, pos int) *lsproto.SelectionRange { |
| 32 | factory := &ast.NodeFactory{} |
| 33 | |
| 34 | nodeContainsPosition := func(node *ast.Node) bool { |
| 35 | if node == nil { |
| 36 | return false |
| 37 | } |
| 38 | start := scanner.GetTokenPosOfNode(node, sourceFile, true /*includeJSDoc*/) |
| 39 | end := node.End() |
| 40 | return start <= pos && pos < end |
| 41 | } |
| 42 | |
| 43 | pushSelectionRange := func(current *lsproto.SelectionRange, start, end int) *lsproto.SelectionRange { |
| 44 | if start == end { |
| 45 | return current |
| 46 | } |
| 47 | |
| 48 | if !(start <= pos && pos <= end) { |
| 49 | return current |
| 50 | } |
| 51 | |
| 52 | lspRange := l.converters.ToLSPRange(sourceFile, core.NewTextRange(start, end)) |
| 53 | |
| 54 | if current != nil && current.Range == lspRange { |
| 55 | return current |
| 56 | } |
| 57 | |
| 58 | return &lsproto.SelectionRange{ |
| 59 | Range: lspRange, |
| 60 | Parent: current, |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | pushSelectionCommentRange := func(current *lsproto.SelectionRange, start, end int) *lsproto.SelectionRange { |
| 65 | current = pushSelectionRange(current, start, end) |
| 66 | |
| 67 | commentPos := start |
| 68 | text := sourceFile.Text() |
| 69 | for commentPos < end && commentPos < len(text) && text[commentPos] == '/' { |
| 70 | commentPos++ |
| 71 | } |
| 72 | current = pushSelectionRange(current, commentPos, end) |
| 73 | |
| 74 | return current |
| 75 | } |
| 76 | |
| 77 | positionsAreOnSameLine := func(pos1, pos2 int) bool { |
| 78 | if pos1 == pos2 { |
| 79 | return true |
| 80 | } |
| 81 | lspPos1 := l.converters.PositionToLineAndCharacter(sourceFile, core.TextPos(pos1)) |
| 82 | lspPos2 := l.converters.PositionToLineAndCharacter(sourceFile, core.TextPos(pos2)) |
| 83 | return lspPos1.Line == lspPos2.Line |
| 84 | } |
| 85 | |
| 86 | shouldSkipNode := func(node *ast.Node, parent *ast.Node) bool { |
| 87 | if ast.IsBlock(node) { |
| 88 | return true |
no test coverage detected