22
33import com .sourcegraph .scip .LocalSymbolsCache ;
44import com .sourcegraph .scip .ScipDocumentBuilder ;
5+ import com .sourcegraph .scip .ScipRange ;
56import com .sourcegraph .scip .ScipSymbols ;
67import com .sun .source .tree .AnnotatedTypeTree ;
78import com .sun .source .tree .ClassTree ;
@@ -182,7 +183,7 @@ private void resolveMethodTree(MethodTree node, TreePath treePath) {
182183 private void resolveVariableTree (VariableTree node , TreePath treePath ) {
183184 Element sym = trees .getElement (treePath );
184185 if (sym == null ) return ;
185- int [] range =
186+ ScipRange range =
186187 emitDefinition (sym , node , sym .getSimpleName (), CompilerRange .FROM_POINT_WITH_TEXT_SEARCH );
187188 if (sym .getKind () == ElementKind .ENUM_CONSTANT ) {
188189 TreePath typeTreePath = nodes .get (node .getInitializer ());
@@ -246,8 +247,8 @@ private void resolveNewClassTree(NewClassTree node, TreePath treePath) {
246247 // =======================================
247248 // Occurrence + SymbolInformation emission
248249 // =======================================
249- private int [] emitDefinition (Element sym , Tree tree , Name name , CompilerRange kind ) {
250- int [] range = computeRange (tree , kind , sym , name == null ? null : name .toString ());
250+ private ScipRange emitDefinition (Element sym , Tree tree , Name name , CompilerRange kind ) {
251+ ScipRange range = computeRange (tree , kind , sym , name == null ? null : name .toString ());
251252 if (range == null ) return null ;
252253 emitOccurrence (sym , range , SymbolRole .Definition_VALUE , computeEnclosingRange (tree ));
253254 declTrees .put (sym , tree );
@@ -256,18 +257,26 @@ private int[] emitDefinition(Element sym, Tree tree, Name name, CompilerRange ki
256257 }
257258
258259 private void emitReference (Element sym , Tree tree , Name name , CompilerRange kind ) {
259- int [] range = computeRange (tree , kind , sym , name == null ? null : name .toString ());
260+ ScipRange range = computeRange (tree , kind , sym , name == null ? null : name .toString ());
260261 if (range == null ) return ;
261262 emitOccurrence (sym , range , 0 /* reference */ , null );
262263 }
263264
264- private void emitOccurrence (Element sym , int [] range , int role , int [] enclosingRange ) {
265+ private void emitOccurrence (Element sym , ScipRange range , int role , ScipRange enclosingRange ) {
265266 String symbol = scipSymbol (sym );
266267 if (symbol .isEmpty ()) return ;
267268 Occurrence .Builder b = Occurrence .newBuilder ().setSymbol (symbol ).setSymbolRoles (role );
268- for (int v : range ) b .addRange (v );
269+ if (range .isSingleLine ()) {
270+ b .setSingleLineRange (range .toSingleLineRange ());
271+ } else {
272+ b .setMultiLineRange (range .toMultiLineRange ());
273+ }
269274 if (enclosingRange != null ) {
270- for (int v : enclosingRange ) b .addEnclosingRange (v );
275+ if (enclosingRange .isSingleLine ()) {
276+ b .setSingleLineEnclosingRange (enclosingRange .toSingleLineRange ());
277+ } else {
278+ b .setMultiLineEnclosingRange (enclosingRange .toMultiLineRange ());
279+ }
271280 }
272281 documentBuilder .addOccurrence (b .build ());
273282 }
@@ -360,7 +369,7 @@ private SymbolInformation.Kind scipKind(Element sym) {
360369 // =======================================
361370 // Source position / range computation
362371 // =======================================
363- private int [] computeRange (Tree tree , CompilerRange kind , Element sym , String name ) {
372+ private ScipRange computeRange (Tree tree , CompilerRange kind , Element sym , String name ) {
364373 if (sym == null ) return null ;
365374 SourcePositions sourcePositions = trees .getSourcePositions ();
366375 int start = (int ) sourcePositions .getStartPosition (compUnitTree , tree );
@@ -394,7 +403,7 @@ private int[] computeRange(Tree tree, CompilerRange kind, Element sym, String na
394403 return lineMapRange (start , end );
395404 }
396405
397- private int [] computeEnclosingRange (Tree tree ) {
406+ private ScipRange computeEnclosingRange (Tree tree ) {
398407 if (tree == null ) return null ;
399408 TreePath path = nodes .get (tree );
400409 if (path == null ) return null ;
@@ -413,7 +422,7 @@ private int[] computeEnclosingRange(Tree tree) {
413422 return lineMapRange (start , end );
414423 }
415424
416- private int [] lineMapRange (int start , int end ) {
425+ private ScipRange lineMapRange (int start , int end ) {
417426 if (start == Diagnostic .NOPOS || end == Diagnostic .NOPOS || end <= start ) return null ;
418427 LineMap lineMap = compUnitTree .getLineMap ();
419428 int startLine = (int ) lineMap .getLineNumber (start ) - 1 ;
@@ -431,8 +440,8 @@ private int[] lineMapRange(int start, int end) {
431440 endChar -= count * 7 ;
432441 }
433442
434- if (startLine == endLine ) return new int [] { startLine , startChar , endChar } ;
435- return new int [] { startLine , startChar , endLine , endChar } ;
443+ if (startLine == endLine ) return ScipRange . singleLine ( startLine , startChar , endChar ) ;
444+ return ScipRange . range ( startLine , startChar , endLine , endChar ) ;
436445 }
437446
438447 // =======================================
0 commit comments