Skip to content
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

Update Typescript Language Server to 4.4.3 #7732

Merged
Merged
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 @@ -53,10 +53,12 @@
import java.util.stream.Collectors;
import javax.swing.event.ChangeListener;
import org.eclipse.lsp4j.ClientCapabilities;
import org.eclipse.lsp4j.DiagnosticWorkspaceCapabilities;
import org.eclipse.lsp4j.DocumentSymbolCapabilities;
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.InitializedParams;
import org.eclipse.lsp4j.PublishDiagnosticsCapabilities;
import org.eclipse.lsp4j.ResourceOperationKind;
import org.eclipse.lsp4j.SemanticTokens;
import org.eclipse.lsp4j.SemanticTokensCapabilities;
Expand Down Expand Up @@ -427,6 +429,8 @@ private static InitializeResult initServer(Process p, LanguageServer server, Fil
wcc.getWorkspaceEdit().setResourceOperations(Arrays.asList(ResourceOperationKind.Create, ResourceOperationKind.Delete, ResourceOperationKind.Rename));
SymbolCapabilities sc = new SymbolCapabilities(new SymbolKindCapabilities(Arrays.asList(SymbolKind.values())));
wcc.setSymbol(sc);
PublishDiagnosticsCapabilities publishDiagnostics = new PublishDiagnosticsCapabilities();
tdcc.setPublishDiagnostics(publishDiagnostics);
initParams.setCapabilities(new ClientCapabilities(wcc, tdcc, null));
CompletableFuture<InitializeResult> initResult = server.initialize(initParams);
while (true) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand All @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.netbeans.modules.lsp.client;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand All @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.netbeans.modules.lsp.client.bindings;

import com.vladsch.flexmark.html.HtmlRenderer;
Expand All @@ -28,6 +29,8 @@
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
Expand Down Expand Up @@ -79,6 +82,8 @@
@MimeRegistration(mimeType="", service=CompletionProvider.class)
public class CompletionProviderImpl implements CompletionProvider {

private static final Logger LOG = Logger.getLogger(CompletionProviderImpl.class.getName());

@Override
public CompletionTask createTask(int queryType, JTextComponent component) {
if ((queryType & TOOLTIP_QUERY_TYPE) != 0) {
Expand Down Expand Up @@ -268,7 +273,7 @@ protected void query(CompletionResultSet resultSet, Document doc, int caretOffse
try {
temp = server.getTextDocumentService().resolveCompletionItem(i).get();
} catch (InterruptedException | ExecutionException ex) {
Exceptions.printStackTrace(ex);
LOG.log(Level.INFO, "Failed to retrieve documentation data", ex);
temp = i;
}
resolved = temp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand All @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.netbeans.modules.lsp.client.bindings;

import java.util.EnumSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void publishDiagnostics(PublishDiagnosticsParams pdp) {
}
assert file != null;
List<ErrorDescription> diags = pdp.getDiagnostics().stream().map(d -> {
LazyFixList fixList = allowCodeActions ? new DiagnosticFixList(pdp.getUri(), d) : ErrorDescriptionFactory.lazyListForFixes(Collections.emptyList());
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);
Expand Down Expand Up @@ -302,12 +302,14 @@ private final class DiagnosticFixList implements LazyFixList {

private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
private final String fileUri;
private final Document doc;
private final Diagnostic diagnostic;
private List<Fix> fixes;
private boolean computing;
private boolean computed;

public DiagnosticFixList(String fileUri, Diagnostic diagnostic) {
public DiagnosticFixList(Document doc, String fileUri, Diagnostic diagnostic) {
this.doc = doc;
this.fileUri = fileUri;
this.diagnostic = diagnostic;
}
Expand All @@ -334,17 +336,19 @@ public synchronized List<Fix> getFixes() {
computing = true;
bindings.runOnBackground(() -> {
try {
List<Either<Command, CodeAction>> commands =
bindings.getTextDocumentService().codeAction(new CodeActionParams(new TextDocumentIdentifier(fileUri),
diagnostic.getRange(),
new CodeActionContext(Collections.singletonList(diagnostic)))).get();

List<Fix> newFixes = Collections.emptyList();

if (commands != null) {
newFixes = commands.stream()
.map(cmd -> new CommandBasedFix(cmd))
.collect(Collectors.toList());
if (Utils.getOffset(doc, diagnostic.getRange().getEnd()) < doc.getEndPosition().getOffset()) {
List<Either<Command, CodeAction>> commands
= bindings.getTextDocumentService().codeAction(new CodeActionParams(new TextDocumentIdentifier(fileUri),
diagnostic.getRange(),
new CodeActionContext(Collections.singletonList(diagnostic)))).get();

if (commands != null) {
newFixes = commands.stream()
.map(cmd -> new CommandBasedFix(cmd))
.collect(Collectors.toList());
}
}

synchronized (this) {
Expand All @@ -355,7 +359,7 @@ public synchronized List<Fix> getFixes() {
pcs.firePropertyChange(PROP_COMPUTED, null, null);
pcs.firePropertyChange(PROP_FIXES, null, null);
} catch (InterruptedException | ExecutionException ex) {
Exceptions.printStackTrace(ex);
LOG.log(Level.INFO, "Failure fetching DiagnosticFixList (at least typescript server has known problems)", ex);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public void run(LSPBindings bindings, FileObject file) {
int lastColumn = 0;
int offset = 0;
for (int i = 0; i < data.size(); i += 5) {
int deltaLine = data.get(i).intValue();
int deltaColumn = data.get(i + 1).intValue();
int deltaLine = data.get(i);
int deltaColumn = data.get(i + 1);
if (deltaLine == 0) {
lastColumn += deltaColumn;
offset += deltaColumn;
Expand All @@ -97,11 +97,11 @@ public void run(LSPBindings bindings, FileObject file) {
lastColumn = deltaColumn;
offset = Utils.getOffset(doc, new Position(lastLine, lastColumn));
}
if (data.get(i + 2).intValue() <= 0) {
if (data.get(i + 2) <= 0) {
continue; //XXX!
}
AttributeSet tokenHighlight = fcs == null ? EMPTY : tokenHighlight(bindings, fcs, data.get(i + 3).intValue(), data.get(i + 4).intValue());
target.addHighlight(offset, offset + data.get(i + 2).intValue(), tokenHighlight);
AttributeSet tokenHighlight = fcs == null ? EMPTY : tokenHighlight(bindings, fcs, data.get(i + 3), data.get(i + 4));
target.addHighlight(offset, offset + data.get(i + 2), tokenHighlight);
}
getBag(doc).setHighlights(target);
} catch (InterruptedException | ExecutionException ex) {
Expand All @@ -111,6 +111,7 @@ public void run(LSPBindings bindings, FileObject file) {

private final Map<Integer, Map<Integer, AttributeSet>> tokenId2Highlight = new HashMap<>();

@SuppressWarnings("AssignmentToMethodParameter")
private AttributeSet tokenHighlight(final LSPBindings bindings, final FontColorSettings fcs, int tokenId, int modifiers) {
assert fcs != null;
return tokenId2Highlight.computeIfAbsent(tokenId, s -> new HashMap<>())
Expand All @@ -121,7 +122,7 @@ private AttributeSet tokenHighlight(final LSPBindings bindings, final FontColorS
//invalid token id
return EMPTY;
}
String tokenName = tokenTypes.get(tokenId);
String tokenName = tokenId >= 0 ? tokenTypes.get(tokenId) : null;
boolean isStatic = false;
boolean isDeclaration = false;
while (mods != 0) {
Expand All @@ -134,7 +135,7 @@ private AttributeSet tokenHighlight(final LSPBindings bindings, final FontColorS
mods &= ~mod;
}

String colorSet = "mod-" + tokenName + (isDeclaration ? "-declaration" : "");
String colorSet = "mod" + (tokenName != null ? ("-" + tokenName) : "") + (isDeclaration ? "-declaration" : "");
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "LSP Semantic coloring. token kind: {0}", colorSet);
}
Expand All @@ -159,14 +160,15 @@ private static OffsetsBag getBag(Document doc) {
OffsetsBag bag = (OffsetsBag) doc.getProperty(SemanticHighlight.class);

if (bag == null) {
doc.putProperty(SemanticHighlight.class, bag = new OffsetsBag(doc));
bag = new OffsetsBag(doc);
doc.putProperty(SemanticHighlight.class, bag);
}

return bag;
}

private static AttributeSet adjustAttributes(AttributeSet as) {
Collection<Object> attrs = new LinkedList<Object>();
Collection<Object> attrs = new LinkedList<>();

for (Enumeration<?> e = as.getAttributeNames(); e.hasMoreElements(); ) {
Object key = e.nextElement();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand All @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.netbeans.modules.lsp.client.bindings;

import java.util.ArrayList;
Expand Down Expand Up @@ -302,6 +303,7 @@ private void ensureDidOpenSent(Document doc) {
}
});

// @todo: the mimetype is not the language ID
TextDocumentItem textDocumentItem = new TextDocumentItem(uri,
FileUtil.getMIMEType(file),
0,
Expand Down
Loading
Loading