diff --git a/prometeu-studio/src/main/java/p/studio/workspaces/editor/EditorWorkspace.java b/prometeu-studio/src/main/java/p/studio/workspaces/editor/EditorWorkspace.java index 9e1a1dd4..cf9d3cc7 100644 --- a/prometeu-studio/src/main/java/p/studio/workspaces/editor/EditorWorkspace.java +++ b/prometeu-studio/src/main/java/p/studio/workspaces/editor/EditorWorkspace.java @@ -388,6 +388,7 @@ public final class EditorWorkspace extends Workspace { openFileSession.open(bufferFrom(updatedDocument)); pendingCaretContextRestore = true; refreshEditableHighlighting(updatedDocument); + refreshEditableSemanticState(updatedDocument); statusBar.showDocumentFormatting(updatedDocument.lineSeparator(), indentationSetup.statusLabel()); tabStrip.showOpenFiles( openFileSession.openFiles(), @@ -405,6 +406,29 @@ public final class EditorWorkspace extends Workspace { preserveViewport(() -> codeArea.setStyleSpans(0, inlineHintProjection.displayStyles())); } + private void refreshEditableSemanticState(final VfsDocumentOpenResult.VfsTextDocument updatedDocument) { + final EditorOpenFileBuffer fileBuffer = openFileSession.activeFile().orElse(null); + if (fileBuffer == null || !fileBuffer.path().equals(updatedDocument.path())) { + return; + } + if (!updatedDocument.accessContext().frontendDocument()) { + scopeGuideModel = EditorDocumentScopeGuideModel.empty(); + activeGuides = EditorDocumentScopeGuideModel.ActiveGuides.empty(); + activeGuideParagraph = -1; + refreshParagraphGraphics(); + outlinePanel.showPlaceholder(); + helperPanel.showPlaceholder(); + return; + } + final LspAnalyzeDocumentResult analysis = prometeuLspService.analyzeDocument( + new LspAnalyzeDocumentRequest(updatedDocument.path())); + scopeGuideModel = guidesFor(fileBuffer, analysis); + activeGuides = scopeGuideModel.resolveActiveGuides(codeArea.getCaretPosition()); + activeGuideParagraph = codeArea.getCurrentParagraph(); + refreshParagraphGraphics(); + refreshSemanticOutline(fileBuffer, analysis); + } + private void preserveViewport(final Runnable action) { final int caretPosition = codeArea.getCaretPosition(); final double scrollX = codeArea.estimatedScrollXProperty().getValue(); @@ -575,10 +599,11 @@ public final class EditorWorkspace extends Workspace { if (Objects.equals(activeGuides, next) && activeGuideParagraph == currentParagraph) { return; } + final boolean guidesChanged = !Objects.equals(activeGuides, next); activeGuides = next; final boolean paragraphChanged = activeGuideParagraph != currentParagraph; activeGuideParagraph = currentParagraph; - if (!paragraphChanged) { + if (!paragraphChanged && !guidesChanged) { return; } refreshParagraphGraphics();