Skip to content

Commit cb70231

Browse files
authored
Merge pull request #2 from PERBILITY/release
Release
2 parents 7bd64cd + 21920bf commit cb70231

File tree

7 files changed

+91
-29
lines changed

7 files changed

+91
-29
lines changed

build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ intellij {
3030
}
3131

3232
dependencies {
33-
compile group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: '0.10.0'
34-
compile group: 'com.vladsch.flexmark', name: 'flexmark', version: '0.34.60'
35-
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
36-
testCompile group: 'junit', name: 'junit', version: '4.13.2'
37-
testCompile group: 'org.mockito', name: 'mockito-core', version: '3.9.0'
38-
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.9'
39-
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.9'
33+
implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: '0.10.0'
34+
implementation group: 'com.vladsch.flexmark', name: 'flexmark', version: '0.34.60'
35+
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
36+
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
37+
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.9.0'
38+
testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.9'
39+
testImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.9'
4040
}
4141

4242
sourceSets {

src/main/java/org/wso2/lsp4intellij/client/connection/ProcessStreamConnectionProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public ProcessStreamConnectionProvider(@NotNull ProcessBuilder processBuilder) {
5656

5757
public void start() throws IOException {
5858
if ((workingDir == null || commands == null || commands.isEmpty() || commands.contains(null)) && builder == null) {
59-
throw new IOException("Unable to start language server: " + this.toString());
59+
throw new IOException("Unable to start language server: " + this);
6060
}
6161
ProcessBuilder builder = createProcessBuilder();
6262
LOG.info("Starting server process with commands " + commands + " and workingDir " + workingDir);
6363
process = builder.start();
6464
if (!process.isAlive()) {
65-
throw new IOException("Unable to start language server: " + this.toString());
65+
throw new IOException("Unable to start language server, process is not alive: " + this);
6666
} else {
6767
LOG.info("Server process started " + process);
6868
}

src/main/java/org/wso2/lsp4intellij/contributors/annotator/LSPAnnotator.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.intellij.openapi.util.TextRange;
2626
import com.intellij.openapi.vfs.VirtualFile;
2727
import com.intellij.psi.PsiFile;
28+
import com.intellij.util.SmartList;
2829
import org.eclipse.lsp4j.Diagnostic;
2930
import org.eclipse.lsp4j.DiagnosticSeverity;
3031
import org.eclipse.lsp4j.DiagnosticTag;
@@ -39,7 +40,6 @@
3940
import org.wso2.lsp4intellij.utils.FileUtils;
4041

4142
import java.util.ArrayList;
42-
import java.util.ConcurrentModificationException;
4343
import java.util.HashMap;
4444
import java.util.List;
4545

@@ -75,10 +75,6 @@ public Object collectInformation(@NotNull PsiFile file, @NotNull Editor editor,
7575
return null;
7676
}
7777

78-
// If the diagnostics list is locked, we need to skip annotating the file.
79-
if (!(eventManager.isDiagnosticSyncRequired() || eventManager.isCodeActionSyncRequired())) {
80-
return null;
81-
}
8278
return RESULT;
8379
} catch (Exception e) {
8480
return null;
@@ -93,7 +89,14 @@ public Object doAnnotate(Object collectedInfo) {
9389

9490
@Override
9591
public void apply(@NotNull PsiFile file, Object annotationResult, @NotNull AnnotationHolder holder) {
96-
92+
if (file.getVirtualFile() == null) {
93+
LOG.warn("file == null || file.getVirtualFile() == null || file.getProject() == null: " + this);
94+
return;
95+
}
96+
if (LanguageServerWrapper.forVirtualFile(file.getVirtualFile(), file.getProject()) == null) {
97+
LOG.warn("LanguageServerWrapper.forVirtualFile(file.getVirtualFile(), file.getProject()): " + this);
98+
return;
99+
}
97100
if (LanguageServerWrapper.forVirtualFile(file.getVirtualFile(), file.getProject()).getStatus() != ServerStatus.INITIALIZED) {
98101
return;
99102
}
@@ -104,6 +107,13 @@ public void apply(@NotNull PsiFile file, Object annotationResult, @NotNull Annot
104107
// TODO annotations are applied to a file / document not to an editor. so store them by file and not by editor..
105108
EditorEventManager eventManager = EditorEventManagerBase.forUri(uri);
106109

110+
// If the diagnostics list is locked, we need to skip annotating the file.
111+
if (!(eventManager.isDiagnosticSyncRequired() || eventManager.isCodeActionSyncRequired())) {
112+
// return;
113+
}
114+
115+
createAnnotations(holder, eventManager);
116+
/*
107117
if (eventManager.isCodeActionSyncRequired()) {
108118
try {
109119
updateAnnotations(holder, eventManager);
@@ -122,7 +132,13 @@ public void apply(@NotNull PsiFile file, Object annotationResult, @NotNull Annot
122132
} catch (Throwable t) {
123133
LOG.warn("Error occurred when updating LSP code actions.", t);
124134
}
135+
} else{
136+
LOG.warn("no annotations");
125137
}
138+
139+
*/
140+
}else{
141+
LOG.warn("no annotations");
126142
}
127143
}
128144

@@ -150,9 +166,13 @@ protected Annotation createAnnotation(Editor editor, AnnotationHolder holder, Di
150166
}
151167
final TextRange range = new TextRange(start, end);
152168

153-
return holder.newAnnotation(lspToIntellijAnnotationsMap.get(diagnostic.getSeverity()), diagnostic.getMessage())
169+
// Revert change from c05c7abe because createAnnotation() causes deprecation exception
170+
holder.newAnnotation(lspToIntellijAnnotationsMap.get(diagnostic.getSeverity()), diagnostic.getMessage())
154171
.range(range)
155-
.createAnnotation();
172+
.create();
173+
SmartList<Annotation> asList = (SmartList<Annotation>) holder;
174+
175+
return asList.get(asList.size() - 1);
156176
}
157177

158178
private void createAnnotations(AnnotationHolder holder, EditorEventManager eventManager) {

src/main/java/org/wso2/lsp4intellij/contributors/psi/LSPPsiElement.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@
4848
import com.intellij.util.IncorrectOperationException;
4949
import com.intellij.util.concurrency.AtomicFieldUpdater;
5050
import com.intellij.util.keyFMap.KeyFMap;
51+
import org.eclipse.lsp4j.Location;
52+
import org.eclipse.lsp4j.Range;
5153
import org.jetbrains.annotations.NotNull;
52-
import org.wso2.lsp4intellij.utils.ApplicationUtils;
54+
import org.wso2.lsp4intellij.editor.EditorEventManager;
55+
import org.wso2.lsp4intellij.editor.EditorEventManagerBase;
56+
import org.wso2.lsp4intellij.utils.DocumentUtils;
5357
import org.wso2.lsp4intellij.utils.FileUtils;
5458

5559
import javax.annotation.Nullable;
5660
import javax.swing.*;
5761

62+
import static org.wso2.lsp4intellij.utils.ApplicationUtils.invokeAfterPsiEvents;
63+
import static org.wso2.lsp4intellij.utils.ApplicationUtils.writeAction;
64+
5865
/**
5966
* A simple PsiElement for LSP
6067
*/
@@ -720,13 +727,28 @@ public String getName() {
720727
}
721728

722729
public void navigate(boolean requestFocus) {
723-
Editor editor = FileUtils.editorFromPsiFile(getContainingFile());
724-
if (editor == null) {
725-
OpenFileDescriptor descriptor = new OpenFileDescriptor(getProject(), getContainingFile().getVirtualFile(),
726-
getTextOffset());
727-
ApplicationUtils.invokeLater(() -> ApplicationUtils
728-
.writeAction(() -> FileEditorManager.getInstance(getProject()).openTextEditor(descriptor, false)));
729-
}
730+
writeAction(() -> {
731+
Editor editor = FileUtils.editorFromPsiFile(getContainingFile());
732+
if (editor == null) {
733+
OpenFileDescriptor descriptor = new OpenFileDescriptor(getProject(), getContainingFile().getVirtualFile(),
734+
getTextOffset());
735+
736+
editor = FileEditorManager.getInstance(getProject()).openTextEditor(descriptor, false);
737+
}
738+
739+
Editor finalEditor = editor;
740+
invokeAfterPsiEvents(() -> {
741+
EditorEventManager manager = EditorEventManagerBase.forEditor(finalEditor);
742+
if (manager != null) {
743+
manager.gotoLocation(
744+
new Location(
745+
FileUtils.uriFromVirtualFile(getContainingFile().getVirtualFile()),
746+
new Range(
747+
DocumentUtils.offsetToLSPPos(finalEditor, this.start),
748+
DocumentUtils.offsetToLSPPos(finalEditor, this.end))));
749+
}
750+
});
751+
});
730752
}
731753

732754
/**

src/main/java/org/wso2/lsp4intellij/statusbar/LSPServerStatusWidget.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.intellij.openapi.actionSystem.DataContext;
2222
import com.intellij.openapi.actionSystem.DefaultActionGroup;
2323
import com.intellij.openapi.components.ServiceManager;
24+
import com.intellij.openapi.diagnostic.Logger;
2425
import com.intellij.openapi.project.DumbAware;
2526
import com.intellij.openapi.project.Project;
2627
import com.intellij.openapi.ui.Messages;
@@ -54,6 +55,7 @@
5455

5556
public class LSPServerStatusWidget implements StatusBarWidget {
5657

58+
private static final Logger LOG = Logger.getInstance(LSPServerStatusWidget.class);
5759
private final Map<Timeouts, Pair<Integer, Integer>> timeouts = new HashMap<>();
5860
private final Project project;
5961
private final String projectName;
@@ -112,7 +114,11 @@ public void dispose() {
112114
if (statusBar != null)
113115
ApplicationUtils.invokeLater(() -> {
114116
StatusBarWidgetFactory factory = ServiceManager.getService(StatusBarWidgetFactory.class);
115-
factory.disposeWidget(this);
117+
if (factory != null) {
118+
factory.disposeWidget(this);
119+
} else {
120+
LOG.warn("factory is null in dispose(): " + this);
121+
}
116122
});
117123
}
118124
}
@@ -147,6 +153,10 @@ public Consumer<MouseEvent> getClickConsumer() {
147153
JBPopupFactory.ActionSelectionAid mnemonics = JBPopupFactory.ActionSelectionAid.MNEMONICS;
148154
Component component = t.getComponent();
149155
List<AnAction> actions = new ArrayList<>();
156+
if (LanguageServerWrapper.forProject(project) == null) {
157+
LOG.warn("LanguageServerWrapper.forProject(project) is null: " + this);
158+
return;
159+
}
150160
if (LanguageServerWrapper.forProject(project).getStatus() == ServerStatus.INITIALIZED) {
151161
actions.add(new ShowConnectedFiles());
152162
}
@@ -227,7 +237,7 @@ public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
227237
public String getTooltipText() {
228238
LanguageServerWrapper wrapper = LanguageServerWrapper.forProject(project);
229239
if (wrapper == null) {
230-
return "Language server, project " + projectName;
240+
return "Language server wrapper is null for project " + projectName;
231241
} else {
232242
return "Language server for extension " + wrapper.getServerDefinition().ext + ", project " + projectName;
233243
}

src/main/java/org/wso2/lsp4intellij/utils/ApplicationUtils.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package org.wso2.lsp4intellij.utils;
1717

1818
import com.intellij.openapi.application.ApplicationManager;
19-
import com.intellij.openapi.application.ModalityState;
19+
import com.intellij.openapi.diagnostic.Logger;
2020
import com.intellij.openapi.project.NoAccessDuringPsiEvents;
2121
import com.intellij.openapi.util.Computable;
2222
import com.intellij.openapi.util.Condition;
@@ -29,6 +29,7 @@
2929

3030
public class ApplicationUtils {
3131

32+
private static final Logger LOG = Logger.getInstance(ApplicationUtils.class);
3233
private static ExecutorService EXECUTOR_SERVICE;
3334

3435
static {
@@ -49,7 +50,11 @@ static public void invokeLater(Runnable runnable) {
4950
}
5051

5152
static public void pool(Runnable runnable) {
52-
EXECUTOR_SERVICE.submit(runnable);
53+
try {
54+
EXECUTOR_SERVICE.submit(runnable);
55+
} catch(Exception e) {
56+
LOG.warn(e + ": ApplicationUtils");
57+
}
5358
}
5459

5560
static public void restartPool() {

src/main/java/org/wso2/lsp4intellij/utils/FileUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ public static String documentToUri(Document document) {
299299
return sanitizeURI(VFSToURI(FileDocumentManager.getInstance().getFile(document)));
300300
}
301301

302+
@Nullable
303+
public static String uriFromVirtualFile(@NotNull VirtualFile vf) {
304+
return pathToUri(vf.getCanonicalPath());
305+
}
306+
302307
/**
303308
* Object representing the OS type (Windows or Unix)
304309
*/

0 commit comments

Comments
 (0)