Skip to content

Commit 619a224

Browse files
committed
Create helper function for location finding
This to reduce code duplication later on
1 parent 80a5b12 commit 619a224

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

java/src/processing/mode/java/lsp/PdeSymbolFinder.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,29 @@ static public List<? extends Location> searchDeclaration(PreprocSketch ps, int j
7777
System.out.println("declaration is outside of the sketch");
7878
return Collections.emptyList();
7979
}
80-
81-
//Create a location for the found declaration
80+
81+
List<Location> declarationList = new ArrayList<>();
82+
declarationList.add(findLocation(ps, si));
83+
84+
return declarationList;
85+
}
86+
87+
88+
/**
89+
* Looks for a location(range) for a given sketchInterval
90+
*
91+
* @param ps processed sketch, for finding the uri and code
92+
* @param si The interval to find the location for
93+
*
94+
* @return Location(range) inside a file from the workspace
95+
*/
96+
static private Location findLocation(PreprocSketch ps, SketchInterval si) {
8297
SketchCode code = ps.sketch.getCode(si.tabIndex);
8398
String program = code.getProgram();
8499
URI uri = PdeAdapter.pathToUri(code.getFile());
85100

86-
Location location =
87-
PdeAdapter.toLocation(program, si.startTabOffset, si.stopTabOffset, uri);
88-
89-
List<Location> declarationList = new ArrayList<>();
90-
declarationList.add(location);
91-
92-
return declarationList;
101+
return PdeAdapter.toLocation(program, si.startTabOffset, si.stopTabOffset,
102+
uri
103+
);
93104
}
94105
}

0 commit comments

Comments
 (0)