use of org.eclipse.lsp4j.TextDocumentIdentifier in project sts4 by spring-projects.
the class SpringIndexer method scanFiles.
private void scanFiles(WorkspaceFolder directory) {
try {
Map<Optional<IJavaProject>, List<String>> projects = Files.walk(Paths.get(new URI(directory.getUri()))).filter(path -> path.getFileName().toString().endsWith(".java")).filter(Files::isRegularFile).map(path -> path.toAbsolutePath().toString()).collect(Collectors.groupingBy((javaFile) -> projectFinder.find(new TextDocumentIdentifier(new File(javaFile).toURI().toString()))));
projects.forEach((maybeProject, files) -> maybeProject.ifPresent(project -> scanProject(project, files.toArray(new String[0]))));
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project sts4 by spring-projects.
the class SimpleLanguageServer method validateWith.
/**
* Convenience method. Subclasses can call this to use a {@link IReconcileEngine} ported
* from old STS codebase to validate a given {@link TextDocument} and publish Diagnostics.
*/
public void validateWith(TextDocumentIdentifier docId, IReconcileEngine engine) {
CompletableFuture<Void> reconcileSession = this.busyReconcile = new CompletableFuture<Void>();
// Log.debug("Reconciling BUSY");
SimpleTextDocumentService documents = getTextDocumentService();
int requestedVersion = documents.getDocument(docId.getUri()).getVersion();
// Avoid running in the same thread as lsp4j as it can result
// in long "hangs" for slow reconcile providers
Mono.fromRunnable(() -> {
TextDocument doc = documents.getDocument(docId.getUri()).copy();
if (requestedVersion != doc.getVersion()) {
// Do not bother reconciling if document contents is already stale.
return;
}
if (testListener != null) {
testListener.reconcileStarted(docId.getUri(), doc.getVersion());
}
IProblemCollector problems = new IProblemCollector() {
private LinkedHashSet<Diagnostic> diagnostics = new LinkedHashSet<>();
private List<Quickfix> quickfixes = new ArrayList<>();
@Override
public void endCollecting() {
documents.setQuickfixes(docId, quickfixes);
documents.publishDiagnostics(docId, diagnostics);
}
@Override
public void beginCollecting() {
diagnostics.clear();
}
@Override
public void checkPointCollecting() {
// publish what has been collected so far
documents.publishDiagnostics(docId, diagnostics);
}
@Override
public void accept(ReconcileProblem problem) {
try {
DiagnosticSeverity severity = getDiagnosticSeverity(problem);
if (severity != null) {
Diagnostic d = new Diagnostic();
d.setCode(problem.getCode());
d.setMessage(problem.getMessage());
Range rng = doc.toRange(problem.getOffset(), problem.getLength());
d.setRange(rng);
d.setSeverity(severity);
List<QuickfixData<?>> fixes = problem.getQuickfixes();
if (CollectionUtil.hasElements(fixes)) {
for (QuickfixData<?> fix : fixes) {
quickfixes.add(new Quickfix<>(CODE_ACTION_COMMAND_ID, d, fix));
}
}
diagnostics.add(d);
}
} catch (BadLocationException e) {
Log.warn("Invalid reconcile problem ignored", e);
}
}
};
// try {
// Thread.sleep(2000);
// } catch (InterruptedException e) {
// }
engine.reconcile(doc, problems);
}).onErrorResume(error -> {
Log.log(error);
return Mono.empty();
}).doFinally(ignore -> {
reconcileSession.complete(null);
// Log.debug("Reconciler DONE : "+this.busyReconcile.isDone());
}).subscribeOn(RECONCILER_SCHEDULER).subscribe();
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project sts4 by spring-projects.
the class SimpleTextDocumentService method didSave.
@Override
public void didSave(DidSaveTextDocumentParams params) {
// Workaround for PT 147263283, where error markers in STS are lost on document save.
// STS 3.9.0 does not use the LSP4E editor for edit manifest.yml, which correctly retains error markers after save.
// Instead, because the LSP4E editor is missing support for hovers and completions, STS 3.9.0 uses its own manifest editor
// which extends the YEdit editor. This YEdit editor has a problem, where on save, all error markers are deleted.
// When STS uses the LSP4E editor and no longer needs its own YEdit-based editor, the issue with error markers disappearing
// on save should not be a problem anymore, and the workaround below will no longer be needed.
async.execute(() -> {
if (documentSaveListener != null) {
TextDocumentIdentifier docId = params.getTextDocument();
String url = docId.getUri();
Log.debug("didSave: " + url);
if (url != null) {
TextDocument doc = getDocument(url);
documentSaveListener.accept(new TextDocumentSaveChange(doc));
}
}
});
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project sts4 by spring-projects.
the class BootLanguageServerParams method createFallbackProjectCache.
private static JavaProjectsService createFallbackProjectCache(SimpleLanguageServer server) {
CompositeJavaProjectFinder javaProjectFinder = new CompositeJavaProjectFinder();
MavenProjectCache mavenProjectCache = new MavenProjectCache(server, MavenCore.getDefault(), true, Paths.get(IJavaProject.PROJECT_CACHE_FOLDER));
javaProjectFinder.addJavaProjectFinder(new MavenProjectFinder(mavenProjectCache));
GradleProjectCache gradleProjectCache = new GradleProjectCache(server, GradleCore.getDefault(), true, Paths.get(IJavaProject.PROJECT_CACHE_FOLDER));
javaProjectFinder.addJavaProjectFinder(new GradleProjectFinder(gradleProjectCache));
CompositeProjectOvserver projectObserver = new CompositeProjectOvserver(Arrays.asList(mavenProjectCache, gradleProjectCache));
return new JavaProjectsService() {
@Override
public void removeListener(Listener listener) {
projectObserver.removeListener(listener);
}
@Override
public void addListener(Listener listener) {
projectObserver.addListener(listener);
}
@Override
public Optional<IJavaProject> find(TextDocumentIdentifier doc) {
return javaProjectFinder.find(doc);
}
};
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method isInActionScriptComment.
private boolean isInActionScriptComment(TextDocumentPositionParams params) {
TextDocumentIdentifier textDocument = params.getTextDocument();
Path path = LanguageServerUtils.getPathFromLanguageServerURI(textDocument.getUri());
if (path == null || !sourceByPath.containsKey(path)) {
return false;
}
String code = sourceByPath.get(path);
int startComment = code.lastIndexOf("/*", currentOffset - 1);
if (startComment >= 0) {
int endComment = code.indexOf("*/", startComment);
if (endComment > currentOffset) {
return true;
}
}
int startLine = code.lastIndexOf('\n', currentOffset - 1);
if (startLine == -1) {
//we're on the first line
startLine = 0;
}
startComment = code.indexOf("//", startLine);
return startComment != -1 && currentOffset > startComment;
}
Aggregations