Skip to content

Commit

Permalink
Create helper function for location finding
Browse files Browse the repository at this point in the history
This to reduce code duplication later on
  • Loading branch information
Efratror committed Mar 19, 2023
1 parent 80a5b12 commit 619a224
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions java/src/processing/mode/java/lsp/PdeSymbolFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,29 @@ static public List<? extends Location> searchDeclaration(PreprocSketch ps, int j
System.out.println("declaration is outside of the sketch");
return Collections.emptyList();
}

//Create a location for the found declaration

List<Location> declarationList = new ArrayList<>();
declarationList.add(findLocation(ps, si));

return declarationList;
}


/**
* Looks for a location(range) for a given sketchInterval
*
* @param ps processed sketch, for finding the uri and code
* @param si The interval to find the location for
*
* @return Location(range) inside a file from the workspace
*/
static private Location findLocation(PreprocSketch ps, SketchInterval si) {
SketchCode code = ps.sketch.getCode(si.tabIndex);
String program = code.getProgram();
URI uri = PdeAdapter.pathToUri(code.getFile());

Location location =
PdeAdapter.toLocation(program, si.startTabOffset, si.stopTabOffset, uri);

List<Location> declarationList = new ArrayList<>();
declarationList.add(location);

return declarationList;
return PdeAdapter.toLocation(program, si.startTabOffset, si.stopTabOffset,
uri
);
}
}

0 comments on commit 619a224

Please sign in to comment.