-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code folding for groups of imports #214
Labels
Comments
Here's an implementation of folding ranges for imports. However, it seems that creating custom folding ranges disables VSCode's built-in folding detection for blocks surrounded by @Override
public CompletableFuture<List<FoldingRange>> foldingRange(FoldingRangeRequestParams params)
{
return CompletableFutures.computeAsync(compilerWorkspace.getExecutorService(), cancelToken ->
{
cancelToken.checkCanceled();
//don't start the build until all other builds are done
compilerWorkspace.startIdleState();
compilerWorkspace.endIdleState(IWorkspace.NIL_COMPILATIONUNITS_TO_UPDATE);
cancelToken.checkCanceled();
compilerWorkspace.startBuilding();
try
{
TextDocumentIdentifier textDocument = params.getTextDocument();
RoyaleProject project = textDocumentIdentifierToProject(textDocument);
if(project == null)
{
cancelToken.checkCanceled();
return Collections.emptyList();
}
Path path = LanguageServerCompilerUtils.getPathFromLanguageServerURI(textDocument.getUri());
if(path == null)
{
cancelToken.checkCanceled();
return Collections.emptyList();
}
IASNode ast = getAST(path);
if(ast == null)
{
cancelToken.checkCanceled();
return Collections.emptyList();
}
List<FoldingRange> result = new ArrayList<>();
findImportFoldingRanges(ast, result);
cancelToken.checkCanceled();
return result;
}
finally
{
compilerWorkspace.doneBuilding();
}
});
}
private void findImportFoldingRanges(IASNode node, List<FoldingRange> result)
{
FoldingRange range = null;
for(int i = 0; i < node.getChildCount(); i++)
{
IASNode child = node.getChild(i);
if (child instanceof IImportNode)
{
if (range == null)
{
range = new FoldingRange(child.getLine(), child.getEndLine());
range.setKind(FoldingRangeKind.Imports);
}
else
{
range.setEndLine(child.getEndLine());
}
continue;
}
else if(range != null)
{
result.add(range);
range = null;
}
findImportFoldingRanges(child, result);
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to wait on something like FoldingRangeProvider to be exposed in the language server protocol.
https://code.visualstudio.com/updates/v1_22#_folding-provider-api
https://code.visualstudio.com/updates/v1_23#_folding-provider-api
The text was updated successfully, but these errors were encountered: