fix: Even more async syntax highlighting
This commit is contained in:
parent
8e498d75be
commit
ace85c6a5a
2 changed files with 34 additions and 22 deletions
|
@ -23,6 +23,11 @@ Changelog structure reference:
|
|||
#### Error diagnostics (NEW)
|
||||
- Basic diagnostics info from LSP (mostly just trivial syntax errors)
|
||||
|
||||
### Fixed
|
||||
|
||||
#### Syntax Highlighting
|
||||
- Made the logic even more asynchronous, should lead to much less UI stuttering
|
||||
|
||||
## [0.3.1]
|
||||
|
||||
### Added
|
||||
|
|
|
@ -18,6 +18,9 @@ package com.falsepattern.zigbrains;
|
|||
|
||||
import com.falsepattern.zigbrains.lsp.ZLSEditorEventManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.markup.HighlighterLayer;
|
||||
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
|
@ -25,9 +28,12 @@ import com.intellij.openapi.util.Key;
|
|||
import org.wso2.lsp4intellij.editor.EditorEventManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
|
@ -36,6 +42,7 @@ public class HighlightingUtil {
|
|||
|
||||
public static void refreshHighlighting(EditorEventManager eem) {
|
||||
var app = ApplicationManager.getApplication();
|
||||
app.executeOnPooledThread(() -> {
|
||||
if (!(eem instanceof ZLSEditorEventManager manager)) {
|
||||
return;
|
||||
}
|
||||
|
@ -43,13 +50,11 @@ public class HighlightingUtil {
|
|||
if (editor == null) {
|
||||
return;
|
||||
}
|
||||
app.executeOnPooledThread(() -> {
|
||||
if (editor.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
var highlightRanges = manager.semanticHighlighting();
|
||||
var newHash = highlightRanges.hashCode();
|
||||
app.invokeAndWait(() -> {
|
||||
if (editor.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
|
@ -59,17 +64,19 @@ public class HighlightingUtil {
|
|||
return;
|
||||
}
|
||||
markup.putUserData(HL_HASH, newHash);
|
||||
List<Map.Entry<RangeHighlighter, Integer>> highlightersSorted = null;
|
||||
var documentLength = editor.getDocument().getTextLength();
|
||||
for (var range : highlightRanges) {
|
||||
if (range.start() == 0 && range.remove() == -1 && highlightRanges.size() == 1) {
|
||||
markup.removeAllHighlighters();
|
||||
} else if (highlightersSorted == null) {
|
||||
highlightersSorted = new ArrayList<>(Stream.of(markup.getAllHighlighters())
|
||||
var highlightersSorted = new ArrayList<>(Stream.of(WriteAction.computeAndWait(markup::getAllHighlighters))
|
||||
.map(hl -> Map.entry(hl, hl.getStartOffset()))
|
||||
.sorted(Comparator.comparingInt(Map.Entry::getValue))
|
||||
.toList());
|
||||
app.invokeLater(() -> {
|
||||
if (editor.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
if (highlightRanges.size() == 1 && highlightRanges.get(0).start() == 0 && highlightRanges.get(0).remove() == -1) {
|
||||
markup.removeAllHighlighters();
|
||||
}
|
||||
var documentLength = editor.getDocument().getTextLength();
|
||||
for (var range : highlightRanges) {
|
||||
var start = range.start();
|
||||
var toRemove = range.remove();
|
||||
if (toRemove > 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue