Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ public TaskFactoryImpl() {

@Override
protected Collection<? extends SchedulerTask> createTasks(Language language, Snapshot snapshot) {
return Collections.singletonList(new BreadCrumbsTask());
if (language.getStructure() != null) {
// Language#hasStructureScanner has a broken/unusable
// implementation, so support is deduced from the (non-)presence
// of a structure scanner.
return List.of(new BreadCrumbsTask());
} else {
return List.of();
}
}

}
Expand Down
56 changes: 56 additions & 0 deletions ide/lsp.client/licenseinfo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

-->
<licenseinfo>
<fileset>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/attribute.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/class.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/color.gif</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/constant.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/constructor.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/empty.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/enummember.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/enum.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/event.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/field.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/file.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/folder.gif</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/function.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/interface.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/keyword.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/method.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/module.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/operator.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/property.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/reference.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/snippet.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/struct.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/text.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/typeparameter.gif</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/unit.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/value.png</file>
<file>src/org/netbeans/modules/lsp/client/bindings/icons/variable.gif</file>
<file>src/org/netbeans/modules/lsp/client/resources/error_16.png</file>
<file>src/org/netbeans/modules/lsp/client/resources/warning_16.png</file>
<license ref="Apache-2.0-ASF" />
<comment type="COMMENT_UNSUPPORTED" />
</fileset>
</licenseinfo>
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void run(List<LSPBindings> servers, FileObject file) {
capa -> Utils.isEnabled(capa.getDocumentSymbolProvider()),
() -> new DocumentSymbolParams(new TextDocumentIdentifier(Utils.toURI(file))),
(server, params) -> server.getTextDocumentService().documentSymbol(params),
(server, result) -> allSymbols.add(Pair.of(server, result.stream().map(this::toDocumentSymbol).toList())));
(server, result) -> allSymbols.add(Pair.of(server, result == null ? List.of() : result.stream().map(this::toDocumentSymbol).toList())));

this.rootElement = new RootBreadcrumbsElementImpl(file, doc, allSymbols);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
import java.util.Collections;
import java.util.List;
import javax.swing.text.JTextComponent;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionContext;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.modules.editor.NbEditorUtilities;
import org.netbeans.modules.lsp.client.LSPBindings;
Expand Down Expand Up @@ -63,17 +66,23 @@ public List<? extends CodeGenerator> create(Lookup context) {
Utils.createPosition(component.getDocument(), component.getSelectionEnd())),
new CodeActionContext(Collections.emptyList())),
(server, params) -> server.getTextDocumentService().codeAction(params),
(server, result) -> result.forEach(cmd -> output.add(new CodeGenerator() {
@Override
public String getDisplayName() {
return cmd.isLeft() ? cmd.getLeft().getTitle() : cmd.getRight().getTitle();
}
(server, result) -> {
if (result != null) {
for (Either<Command, CodeAction> cmd : result) {
output.add(new CodeGenerator() {
@Override
public String getDisplayName() {
return cmd.isLeft() ? cmd.getLeft().getTitle() : cmd.getRight().getTitle();
}

@Override
public void invoke() {
Utils.applyCodeAction(server, cmd);
}
})));
@Override
public void invoke() {
Utils.applyCodeAction(server, cmd);
}
});
}
}
});

return output;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ private void documentFormat(FileObject fo, LSPBindings bindings) throws BadLocat
IndentUtils.isExpandTabs(ctx.document())));
List<TextEdit> edits = new ArrayList<>();
try {
edits.addAll(bindings.getTextDocumentService().formatting(dfp).get());
List<? extends TextEdit> editInputs = bindings.getTextDocumentService().formatting(dfp).get();
if (editInputs != null) {
edits.addAll(editInputs);
}
} catch (InterruptedException | ExecutionException ex) {
LOG.log(Level.INFO,
String.format("LSP document format failed for {0}", fo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.eclipse.lsp4j.jsonrpc.Endpoint;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageClient;
import org.netbeans.api.annotations.common.StaticResource;
import org.netbeans.api.progress.*;
import org.netbeans.modules.lsp.client.LSPBindings;
import org.netbeans.modules.lsp.client.Utils;
Expand Down Expand Up @@ -98,6 +99,11 @@ public class LanguageClientImpl implements LanguageClient, Endpoint {
private static final Logger LOG = Logger.getLogger(LanguageClientImpl.class.getName());
private static final RequestProcessor WORKER = new RequestProcessor(LanguageClientImpl.class.getName(), 1, false, false);

@StaticResource
private static final String ERROR_ICON = "org/netbeans/modules/lsp/client/resources/error_16.png";
@StaticResource
private static final String WARNING_ICON = "org/netbeans/modules/lsp/client/resources/warning_16.png";

private LSPBindings bindings;
private boolean allowCodeActions;

Expand Down Expand Up @@ -161,24 +167,26 @@ public void notifyProgress(ProgressParams params) {
});
}

@Override
@Override
public void publishDiagnostics(PublishDiagnosticsParams pdp) {
try {
FileObject file = URLMapper.findFileObject(new URI(pdp.getUri()).toURL());
EditorCookie ec = file != null ? file.getLookup().lookup(EditorCookie.class) : null;
Document doc = ec != null ? ec.getDocument() : null;
if (doc == null) {
return ; //ignore...
WORKER.execute(() -> {
try {
FileObject file = URLMapper.findFileObject(new URI(pdp.getUri()).toURL());
EditorCookie ec = file != null ? file.getLookup().lookup(EditorCookie.class) : null;
Document doc = ec != null ? ec.getDocument() : null;
if (doc == null) {
return; //ignore...
}
assert file != null;
List<ErrorDescription> diags = pdp.getDiagnostics().stream().map(d -> {
LazyFixList fixList = allowCodeActions ? new DiagnosticFixList(doc, pdp.getUri(), d) : ErrorDescriptionFactory.lazyListForFixes(Collections.emptyList());
return ErrorDescriptionFactory.createErrorDescription(severityMap.get(d.getSeverity()), d.getMessage(), fixList, file, Utils.getOffset(doc, d.getRange().getStart()), Utils.getOffset(doc, d.getRange().getEnd()));
}).collect(Collectors.toList());
HintsController.setErrors(doc, LanguageClientImpl.class.getName(), diags);
} catch (URISyntaxException | MalformedURLException ex) {
LOG.log(Level.FINE, null, ex);
}
assert file != null;
List<ErrorDescription> diags = pdp.getDiagnostics().stream().map(d -> {
LazyFixList fixList = allowCodeActions ? new DiagnosticFixList(doc, pdp.getUri(), d) : ErrorDescriptionFactory.lazyListForFixes(Collections.emptyList());
return ErrorDescriptionFactory.createErrorDescription(severityMap.get(d.getSeverity()), d.getMessage(), fixList, file, Utils.getOffset(doc, d.getRange().getStart()), Utils.getOffset(doc, d.getRange().getEnd()));
}).collect(Collectors.toList());
HintsController.setErrors(doc, LanguageClientImpl.class.getName(), diags);
} catch (URISyntaxException | MalformedURLException ex) {
LOG.log(Level.FINE, null, ex);
}
});
}

private static final Map<DiagnosticSeverity, Severity> severityMap = new EnumMap<>(DiagnosticSeverity.class);
Expand Down Expand Up @@ -211,11 +219,11 @@ public void showMessage(MessageParams params) {
StatusDisplayer.getDefault().setStatusText(params.getMessage());
return ;
case Warning:
icon = ImageUtilities.loadImageIcon("org/netbeans/modules/lsp/client/resources/warning.png", false);
icon = ImageUtilities.loadImageIcon(WARNING_ICON, false);
category = Category.WARNING;
break;
case Error:
icon = ImageUtilities.loadImageIcon("org/netbeans/modules/lsp/client/resources/error_16.png", false);
icon = ImageUtilities.loadImageIcon(ERROR_ICON, false);
category = Category.ERROR;
break;
}
Expand Down Expand Up @@ -305,6 +313,12 @@ public void notify(String method, Object parameter) {
LOG.log(Level.WARNING, "Received unhandled notification: {0}: {1}", new Object[] {method, parameter});
}

@Override
public CompletableFuture<Void> refreshDiagnostics() {
bindings.getOpenedFiles().forEach(LSPBindings::scheduleBackgroundTasks);
return CompletableFuture.completedFuture(null);
}

private final class DiagnosticFixList implements LazyFixList {

private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void run(FileObject file) {
String uri = Utils.toURI(file);
List<Either<SymbolInformation, DocumentSymbol>> symbols = bindings.getTextDocumentService().documentSymbol(new DocumentSymbolParams(new TextDocumentIdentifier(uri))).get();

setKeys(symbols);
setKeys(symbols == null ? List.of() : symbols);
expandAll();
} catch (ExecutionException ex) {
LOG.log(Level.FINE, null, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ private void convertTokenHighlights(LSPBindings server,
FileObject file,
FontColorSettings[] fcs,
OffsetsBag target) {
List<Integer> data = tokens.getData();
List<Integer> data;
if (tokens != null) {
data = tokens.getData();
} else {
data = List.of();
}
int lastLine = 0;
int lastColumn = 0;
int offset = 0;
Expand Down
Loading
Loading