From c1acbd9398d260b4141bad5395d7ee1e82f86170 Mon Sep 17 00:00:00 2001 From: Maximilien Tirard Date: Mon, 30 Jan 2023 21:11:19 +0000 Subject: [PATCH 01/26] Keyboard shortcut for FR keyboard layout on mac see processing/processing4#625 --- build/shared/lib/languages/PDE_fr.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/build/shared/lib/languages/PDE_fr.properties b/build/shared/lib/languages/PDE_fr.properties index 2e63495062..1b4ff94e3b 100644 --- a/build/shared/lib/languages/PDE_fr.properties +++ b/build/shared/lib/languages/PDE_fr.properties @@ -40,6 +40,7 @@ menu.edit.paste = Coller menu.edit.select_all = Selectionner tout menu.edit.auto_format = Mise en forme automatique menu.edit.comment_uncomment = Commenter/Décommenter +menu.edit.comment_uncomment.keystroke = meta pressed COLON menu.edit.increase_indent = → Augmenter l'indentation menu.edit.decrease_indent = ← Diminuer l'indentation menu.edit.find = Rechercher... From 619a2242e32cea043bb5a9b201beaabf6aa8fcbd Mon Sep 17 00:00:00 2001 From: Efratror Date: Sun, 19 Mar 2023 08:35:07 +0100 Subject: [PATCH 02/26] Create helper function for location finding This to reduce code duplication later on --- .../mode/java/lsp/PdeSymbolFinder.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/java/src/processing/mode/java/lsp/PdeSymbolFinder.java b/java/src/processing/mode/java/lsp/PdeSymbolFinder.java index ac2cd5e14e..919c4e62da 100644 --- a/java/src/processing/mode/java/lsp/PdeSymbolFinder.java +++ b/java/src/processing/mode/java/lsp/PdeSymbolFinder.java @@ -77,18 +77,29 @@ static public List searchDeclaration(PreprocSketch ps, int j System.out.println("declaration is outside of the sketch"); return Collections.emptyList(); } - - //Create a location for the found declaration + + List declarationList = new ArrayList<>(); + declarationList.add(findLocation(ps, si)); + + return declarationList; + } + + + /** + * Looks for a location(range) for a given sketchInterval + * + * @param ps processed sketch, for finding the uri and code + * @param si The interval to find the location for + * + * @return Location(range) inside a file from the workspace + */ + static private Location findLocation(PreprocSketch ps, SketchInterval si) { SketchCode code = ps.sketch.getCode(si.tabIndex); String program = code.getProgram(); URI uri = PdeAdapter.pathToUri(code.getFile()); - Location location = - PdeAdapter.toLocation(program, si.startTabOffset, si.stopTabOffset, uri); - - List declarationList = new ArrayList<>(); - declarationList.add(location); - - return declarationList; + return PdeAdapter.toLocation(program, si.startTabOffset, si.stopTabOffset, + uri + ); } } From 2ca4a377ec33a9ffaa1e1493c6bad385519120d2 Mon Sep 17 00:00:00 2001 From: Efratror Date: Sun, 19 Mar 2023 08:36:41 +0100 Subject: [PATCH 03/26] Bringing out some variables --- java/src/processing/mode/java/ASTUtils.java | 4 +++- java/src/processing/mode/java/SketchInterval.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/java/src/processing/mode/java/ASTUtils.java b/java/src/processing/mode/java/ASTUtils.java index 11d39287c1..bc57f1e45f 100644 --- a/java/src/processing/mode/java/ASTUtils.java +++ b/java/src/processing/mode/java/ASTUtils.java @@ -163,7 +163,9 @@ public static boolean isNameOrType(ASTNode node) { } - protected static List findAllOccurrences(ASTNode root, String bindingKey) { + public static List findAllOccurrences(ASTNode root, + String bindingKey + ) { List occurrences = new ArrayList<>(); root.getRoot().accept(new ASTVisitor() { @Override diff --git a/java/src/processing/mode/java/SketchInterval.java b/java/src/processing/mode/java/SketchInterval.java index e0596bc29f..c7f654f5f1 100644 --- a/java/src/processing/mode/java/SketchInterval.java +++ b/java/src/processing/mode/java/SketchInterval.java @@ -18,6 +18,6 @@ public class SketchInterval { public final int startTabOffset; public final int stopTabOffset; - final int startPdeOffset; - final int stopPdeOffset; + public final int startPdeOffset; + public final int stopPdeOffset; } \ No newline at end of file From 9b54cbc5ea84e8f26a2e0f0f2a80e3d2211e2e8a Mon Sep 17 00:00:00 2001 From: Efratror Date: Sun, 19 Mar 2023 08:38:03 +0100 Subject: [PATCH 04/26] Add reference searching --- .../mode/java/lsp/PdeSymbolFinder.java | 48 ++++++++++++++++++- .../mode/java/lsp/PdeTextDocumentService.java | 33 +++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/java/src/processing/mode/java/lsp/PdeSymbolFinder.java b/java/src/processing/mode/java/lsp/PdeSymbolFinder.java index 919c4e62da..e8f850bc68 100644 --- a/java/src/processing/mode/java/lsp/PdeSymbolFinder.java +++ b/java/src/processing/mode/java/lsp/PdeSymbolFinder.java @@ -18,8 +18,7 @@ import processing.mode.java.PreprocSketch; import processing.mode.java.SketchInterval; -import static processing.mode.java.ASTUtils.getSimpleNameAt; -import static processing.mode.java.ASTUtils.resolveBinding; +import static processing.mode.java.ASTUtils.*; public class PdeSymbolFinder { @@ -85,6 +84,51 @@ static public List searchDeclaration(PreprocSketch ps, int j } + /** + * searches all reference nodes for a provided character offset + * + * @param ps processed sketch, for AST-nodes and sketch + * @param javaOffset character offset for the node we want to look up + * + * @return Location list of all references found, else an empty list. + */ + static public List searchReference(PreprocSketch ps, + int javaOffset + ) { + ASTNode root = ps.compilationUnit; + + SimpleName simpleName = getSimpleNameAt(root, javaOffset, javaOffset); + if (simpleName == null) { + System.out.println("no simple name found at location"); + return Collections.emptyList(); + } + + IBinding binding = resolveBinding(simpleName); + if (binding == null) { + System.out.println("binding not resolved"); + return Collections.emptyList(); + } + + // Find usages + String bindingKey = binding.getKey(); + List referenceIntervals = + findAllOccurrences(ps.compilationUnit, bindingKey).stream() + .map(ps::mapJavaToSketch) + // remove occurrences which fall into generated header + .filter(ps::inRange) + // remove empty intervals (happens when occurence was inserted) + .filter(in -> in.startPdeOffset < in.stopPdeOffset) + .collect(java.util.stream.Collectors.toList()); + + List referenceList = new ArrayList<>(); + for (SketchInterval referenceInterval: referenceIntervals) { + referenceList.add(findLocation(ps, referenceInterval)); + } + + return referenceList; + } + + /** * Looks for a location(range) for a given sketchInterval * diff --git a/java/src/processing/mode/java/lsp/PdeTextDocumentService.java b/java/src/processing/mode/java/lsp/PdeTextDocumentService.java index 4ac167ab87..89f8340dce 100644 --- a/java/src/processing/mode/java/lsp/PdeTextDocumentService.java +++ b/java/src/processing/mode/java/lsp/PdeTextDocumentService.java @@ -17,6 +17,7 @@ import org.eclipse.lsp4j.TextEdit; import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.LocationLink; +import org.eclipse.lsp4j.ReferenceParams; import java.util.Collections; import java.net.URI; @@ -137,4 +138,36 @@ public CompletableFuture, List> references( + ReferenceParams params + ) { + + System.out.println("searching for references"); + URI uri = URI.create(params.getTextDocument().getUri()); + int lineNumber = params.getPosition().getLine(); + int colNumber = params.getPosition().getCharacter(); + + Optional adapterOptional = pls.getAdapter(uri); + if (adapterOptional.isEmpty()) { + System.out.println("pde adapter not found"); + return CompletableFutures.computeAsync(_x -> Collections.emptyList()); + } + PdeAdapter adapter = adapterOptional.get(); + PreprocSketch preprocSketch = adapter.ps; + + Optional optionalJavaOffset = + adapter.findJavaOffset(uri, lineNumber, colNumber); + if (optionalJavaOffset.isEmpty()) { + System.out.println("javaOffset not found"); + return CompletableFutures.computeAsync(_x -> (Collections.emptyList())); + } + + int javaOffset = optionalJavaOffset.get(); + List locations; + locations = PdeSymbolFinder.searchReference(preprocSketch, javaOffset); + + return CompletableFutures.computeAsync(_x -> locations); + } } From cbbb8786ea2085920f7828479db2477049dab9b7 Mon Sep 17 00:00:00 2001 From: Efratror Date: Sun, 19 Mar 2023 08:38:28 +0100 Subject: [PATCH 05/26] Add capabilities to the server --- java/src/processing/mode/java/lsp/PdeLanguageServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/src/processing/mode/java/lsp/PdeLanguageServer.java b/java/src/processing/mode/java/lsp/PdeLanguageServer.java index ee71754cb8..3d865fcc7b 100644 --- a/java/src/processing/mode/java/lsp/PdeLanguageServer.java +++ b/java/src/processing/mode/java/lsp/PdeLanguageServer.java @@ -78,6 +78,7 @@ public CompletableFuture initialize(InitializeParams params) { capabilities.setCompletionProvider(completionOptions); capabilities.setDocumentFormattingProvider(true); capabilities.setDeclarationProvider(true); + capabilities.setReferencesProvider(true); var result = new InitializeResult(capabilities); return CompletableFuture.completedFuture(result); } From b3ee57fa5b79ef8b8f0f3b7ee104eedbb44cc605 Mon Sep 17 00:00:00 2001 From: Efratror Date: Sun, 19 Mar 2023 08:44:12 +0100 Subject: [PATCH 06/26] Follow styleguide for previous code As noted by mr. Fry in PR #678 and issue #684 --- java/src/processing/mode/java/lsp/PdeTextDocumentService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/src/processing/mode/java/lsp/PdeTextDocumentService.java b/java/src/processing/mode/java/lsp/PdeTextDocumentService.java index 89f8340dce..67044c0378 100644 --- a/java/src/processing/mode/java/lsp/PdeTextDocumentService.java +++ b/java/src/processing/mode/java/lsp/PdeTextDocumentService.java @@ -106,7 +106,7 @@ public CompletableFuture, List adapterOptional = pls.getAdapter(uri); - if(adapterOptional.isEmpty()){ + if (adapterOptional.isEmpty()) { System.out.println("pde adapter not found"); return CompletableFutures.computeAsync(_x -> Either .forLeft(Collections.emptyList())); @@ -117,7 +117,7 @@ public CompletableFuture, List optionalJavaOffset = adapter.findJavaOffset(uri, lineNumber, colNumber); - if(optionalJavaOffset.isEmpty()){ + if (optionalJavaOffset.isEmpty()) { System.out.println("javaOffset not found"); return CompletableFutures.computeAsync(_x -> Either .forLeft(Collections.emptyList())); From d76b1740c323a147791bdc269b6419ea65dd10a4 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Thu, 4 May 2023 13:49:28 -0400 Subject: [PATCH 07/26] itext jar as library --- java/libraries/pdf/processing4-pdf.iml | 1 + 1 file changed, 1 insertion(+) diff --git a/java/libraries/pdf/processing4-pdf.iml b/java/libraries/pdf/processing4-pdf.iml index 5d6ac80117..3105266fcb 100644 --- a/java/libraries/pdf/processing4-pdf.iml +++ b/java/libraries/pdf/processing4-pdf.iml @@ -17,5 +17,6 @@ + \ No newline at end of file From 5d1a5a9368ae179edea073581a4154566c7bbcd2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 9 Jul 2023 19:16:56 +0200 Subject: [PATCH 08/26] Update Spanish translation Synchronised with the master version (English). --- build/shared/lib/languages/PDE_es.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/shared/lib/languages/PDE_es.properties b/build/shared/lib/languages/PDE_es.properties index 2ef620b0f0..76bad95d19 100644 --- a/build/shared/lib/languages/PDE_es.properties +++ b/build/shared/lib/languages/PDE_es.properties @@ -138,6 +138,7 @@ menu.help.about = Acerca de Processing menu.help.environment = Entorno de desarrollo menu.help.reference = Referencia menu.help.find_in_reference = Buscar en la referencia +menu.help.reference.download = Descargar la referencia menu.help.libraries_reference = Referencias de bibliotecas menu.help.tools_reference = Referencias de herramientas menu.help.empty = (vacío) @@ -561,7 +562,7 @@ contrib.progress.installing = Instalando contrib.progress.starting = Comenzando contrib.progress.downloading = Descargando contrib.download_error = Ha ocurrido un error durante la descarga de la contribución. -contrib.unsupported_operating_system = Parece que este sistema operativo no es compatible. Consulta la biblioteca de «%s» para más información. +contrib.missing_link = No se ha encontrado el enlace de descarga de %s, contacta con el autor. contrib.category.3d = 3D contrib.category.animation = Animación contrib.category.data = Datos From 442ac460c4718f5d7c3d8bac57f463f1d9afa31d Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 9 Jul 2023 19:18:24 +0200 Subject: [PATCH 09/26] Update Catalan translation Synchronised with the master version (English) --- build/shared/lib/languages/PDE_ca.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/shared/lib/languages/PDE_ca.properties b/build/shared/lib/languages/PDE_ca.properties index 230393f6cc..cdff9ec65b 100644 --- a/build/shared/lib/languages/PDE_ca.properties +++ b/build/shared/lib/languages/PDE_ca.properties @@ -138,6 +138,7 @@ menu.help.about = Quant al Processing menu.help.environment = Entorn de desenvolupament menu.help.reference = Referència menu.help.find_in_reference = Cerca en la referència +menu.help.reference.download = Descarrega la referència menu.help.libraries_reference = Referències de les biblioteques menu.help.tools_reference = Referències de les eines menu.help.empty = (buit) @@ -561,7 +562,7 @@ contrib.progress.installing = S'està instal·lant contrib.progress.starting = Començant instal·lació contrib.progress.downloading = Descarregant contrib.download_error = S'ha produït un error durant la descàrrega de la contribució. -contrib.unsupported_operating_system = Sembla que el vostre sistema operatiu no és compatible. Consulteu la biblioteca de «%s» per a més informació. +contrib.missing_link = No s'ha trobat l'enllaç de descàrrega per a %s, contacteu amb l'autor. contrib.category.3d = 3D contrib.category.animation = Animació contrib.category.data = Dades From 81faaa5e7d475e809c936da2f77b8f46ec32c2ab Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 16 Jul 2023 12:38:45 -0400 Subject: [PATCH 10/26] incorporate some merges and other issues seen in the meantime --- core/todo.txt | 6 ++++-- todo.txt | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/core/todo.txt b/core/todo.txt index c1ae59b5bb..cbe4b3428e 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,10 +1,12 @@ 1293 (4.2.1) -JNA version of getting resolution https://stackoverflow.com/a/32588375 -https://stackoverflow.com/a/32588375 +contribs +_ JNA version of getting resolution +_ https://stackoverflow.com/a/32588375 + _ args passed to main() aren't working _ (there was a bug report for this already?) _ were the run() and runSketch() methods merged w/o realizing loss of args? diff --git a/todo.txt b/todo.txt index 975cb249df..b31ad19cf8 100755 --- a/todo.txt +++ b/todo.txt @@ -1,9 +1,35 @@ 1293 (4.2.1) + +sampottinger +X Syntax error highlighting placement / width incorrect +X https://github.com/processing/processing4/issues/714 +X https://github.com/processing/processing4/pull/715 +X Tweak mode issue with hex codes including transparency +X https://github.com/processing/processing4/issues/720 +X https://github.com/processing/processing4/pull/721 + contribs X LSP feature/declaration support from @Efratror X https://github.com/processing/processing4/pull/678 X https://github.com/processing/processing4/issues/676 +X Update Spanish translation from @trikaphundo +X https://github.com/processing/processing4/issues/744 +X https://github.com/processing/processing4/pull/746 +X Update Catalan translation from @trikaphundo +X https://github.com/processing/processing4/issues/743 +X https://github.com/processing/processing4/pull/745 +X Debugger lists immediate array dimension last from @WillRabois04 +X https://github.com/processing/processing4/issues/606 +X https://github.com/processing/processing4/pull/729 + + +_ ' appearing in code with Copy as HTML + +_ sandbox access to Desktop folder when using non-notarized versions +_ "Security-Scoped Bookmarks" is the term: https://stackoverflow.com/a/12155622 +_ example using JNI: https://github.com/plexteq/PQSsbJNIBridge +_ how to store/save bookmarks: https://stackoverflow.com/a/74835008 _ doing "Save As" on sketch didn't write a new main= entry in sketch.properties From fb20a176ee18341cf01ece1496af1450d6c831fb Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 16 Jul 2023 12:40:21 -0400 Subject: [PATCH 11/26] fix pdf colors outside the range causing NPE (resolves #740) --- core/src/processing/awt/PGraphicsJava2D.java | 57 +++++++++++-------- .../pdf/src/processing/pdf/PGraphicsPDF.java | 8 +++ todo.txt | 3 +- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/core/src/processing/awt/PGraphicsJava2D.java b/core/src/processing/awt/PGraphicsJava2D.java index ee41fe052d..edb3767106 100644 --- a/core/src/processing/awt/PGraphicsJava2D.java +++ b/core/src/processing/awt/PGraphicsJava2D.java @@ -2607,34 +2607,41 @@ public void backgroundImpl() { clearPixels(backgroundColor); } else { - Color bgColor = new Color(backgroundColor); - // seems to fire an additional event that causes flickering, - // like an extra background erase on OS X -// if (canvas != null) { -// canvas.setBackground(bgColor); -// } - //new Exception().printStackTrace(System.out); - // in case people do transformations before background(), - // need to handle this with a push/reset/pop - Composite oldComposite = g2.getComposite(); - g2.setComposite(defaultComposite); + backgroundRect(); + } + } - pushMatrix(); - resetMatrix(); - g2.setColor(bgColor); //, backgroundAlpha)); -// g2.fillRect(0, 0, width, height); - // On a hi-res display, image may be larger than width/height - if (image != null) { - // image will be null in subclasses (i.e. PDF) - g2.fillRect(0, 0, image.getWidth(null), image.getHeight(null)); - } else { - // hope for the best if image is null - g2.fillRect(0, 0, width, height); - } - popMatrix(); - g2.setComposite(oldComposite); + protected void backgroundRect() { + Color bgColor = new Color(backgroundColor); + + // While more complete, this seems to fire an additional event that + // causes flickering, like an extra background erase on OS X. + //if (canvas != null) { + // canvas.setBackground(bgColor); + //} + + // If there are transformations or blending changes at the top of + // draw() (before background() is called) or still in place from + // the last trip through draw(), need to store and re-apply after. + Composite oldComposite = g2.getComposite(); + g2.setComposite(defaultComposite); + pushMatrix(); + resetMatrix(); + + g2.setColor(bgColor); + // On a hi-res display, image may be larger than width/height + if (image != null) { + // image will be null in subclasses (i.e. PDF) + g2.fillRect(0, 0, image.getWidth(null), image.getHeight(null)); + } else { + // hope for the best if image is null + g2.fillRect(0, 0, width, height); } + + // Reset the drawing state (see above) + popMatrix(); + g2.setComposite(oldComposite); } diff --git a/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java b/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java index c0bb22f17f..ea1574908e 100644 --- a/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java +++ b/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java @@ -496,6 +496,14 @@ protected void textLineImpl(char buffer[], int start, int stop, ////////////////////////////////////////////////////////////// + public void backgroundImpl() { + // Override so that even with alpha, we draw a rectangle. + // https://github.com/processing/processing4/issues/740 + backgroundRect(); + } + + // + public void loadPixels() { nope("loadPixels"); } diff --git a/todo.txt b/todo.txt index b31ad19cf8..6f4e33cb0c 100755 --- a/todo.txt +++ b/todo.txt @@ -1,5 +1,6 @@ 1293 (4.2.1) - +X `NullPointerException` when background exceeds color range when writing PDF +X https://github.com/processing/processing4/issues/740 sampottinger X Syntax error highlighting placement / width incorrect From c57069fdca888e614bf52caa4cb7999277ae32e0 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 16 Jul 2023 12:56:08 -0400 Subject: [PATCH 12/26] Use calculated text height instead of OS ascent for better vertical centering (fixes #739) --- core/src/processing/awt/PGraphicsJava2D.java | 8 ++++++++ todo.txt | 2 ++ 2 files changed, 10 insertions(+) diff --git a/core/src/processing/awt/PGraphicsJava2D.java b/core/src/processing/awt/PGraphicsJava2D.java index edb3767106..7d784ee600 100644 --- a/core/src/processing/awt/PGraphicsJava2D.java +++ b/core/src/processing/awt/PGraphicsJava2D.java @@ -1873,10 +1873,16 @@ public float textAscent() { defaultFontOrDeath("textAscent"); } + // This value is dreadfully inaccurate and inconsistent, and especially + // so for the default font. Switching to use our built-in calculation since + // our most common use case is likely textAlign(CENTER, CENTER) with the + // default font, and it needs to work well there. [fry 230716] + /* Font font = (Font) textFont.getNative(); if (font != null) { return g2.getFontMetrics(font).getAscent(); } + */ return super.textAscent(); } @@ -1886,10 +1892,12 @@ public float textDescent() { if (textFont == null) { defaultFontOrDeath("textDescent"); } + /* Font font = (Font) textFont.getNative(); if (font != null) { return g2.getFontMetrics(font).getDescent(); } + */ return super.textDescent(); } diff --git a/todo.txt b/todo.txt index 6f4e33cb0c..318718d2eb 100755 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,8 @@ 1293 (4.2.1) X `NullPointerException` when background exceeds color range when writing PDF X https://github.com/processing/processing4/issues/740 +X Use calculated text height instead of OS ascent for better vertical centering +X https://github.com/processing/processing4/issues/739 sampottinger X Syntax error highlighting placement / width incorrect From 0b8c543a050194302103ca2c43025a7ca03d414d Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 16 Jul 2023 14:38:36 -0400 Subject: [PATCH 13/26] merging more features, going through the todo list --- core/todo.txt | 7 ++++--- todo.txt | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/core/todo.txt b/core/todo.txt index cbe4b3428e..dc3fa8a29c 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,7 +1,8 @@ 1293 (4.2.1) - - -contribs +X `NullPointerException` when background exceeds color range when writing PDF +X https://github.com/processing/processing4/issues/740 +X Use calculated text height instead of OS ascent for better vertical centering +X https://github.com/processing/processing4/issues/739 _ JNA version of getting resolution diff --git a/todo.txt b/todo.txt index 318718d2eb..2051a70492 100755 --- a/todo.txt +++ b/todo.txt @@ -1,21 +1,22 @@ 1293 (4.2.1) -X `NullPointerException` when background exceeds color range when writing PDF -X https://github.com/processing/processing4/issues/740 -X Use calculated text height instead of OS ascent for better vertical centering -X https://github.com/processing/processing4/issues/739 +_ ' appearing in code with Copy as HTML +_ Cannot load any user language files for i18n +_ https://github.com/processing/processing4/issues/722 + -sampottinger -X Syntax error highlighting placement / width incorrect +contribs +X Syntax error highlighting placement / width incorrect from @sampottinger X https://github.com/processing/processing4/issues/714 X https://github.com/processing/processing4/pull/715 -X Tweak mode issue with hex codes including transparency +X Tweak mode issue with hex codes including transparency from @sampottinger X https://github.com/processing/processing4/issues/720 X https://github.com/processing/processing4/pull/721 - -contribs X LSP feature/declaration support from @Efratror X https://github.com/processing/processing4/pull/678 X https://github.com/processing/processing4/issues/676 +X Feature: Language Server Protocol, Reference Support from @Efratror +X https://github.com/processing/processing4/issues/684 +X https://github.com/processing/processing4/pull/690 X Update Spanish translation from @trikaphundo X https://github.com/processing/processing4/issues/744 X https://github.com/processing/processing4/pull/746 @@ -27,7 +28,11 @@ X https://github.com/processing/processing4/issues/606 X https://github.com/processing/processing4/pull/729 -_ ' appearing in code with Copy as HTML +pending +_ comment/uncomment on French systems +_ https://github.com/processing/processing4/issues/625 +_ https://github.com/processing/processing4/pull/660 + _ sandbox access to Desktop folder when using non-notarized versions _ "Security-Scoped Bookmarks" is the term: https://stackoverflow.com/a/12155622 From 83a1ce78c56fbb95ed5221e20d7792ff144b356e Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 16 Jul 2023 16:11:36 -0400 Subject: [PATCH 14/26] not possible to do languages from sketchbook b/c path not available --- app/src/processing/app/Language.java | 16 +++++++++++++--- todo.txt | 11 +++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/processing/app/Language.java b/app/src/processing/app/Language.java index 311abc1be3..d55c8b710c 100644 --- a/app/src/processing/app/Language.java +++ b/app/src/processing/app/Language.java @@ -351,24 +351,34 @@ static class LanguageBundle { LanguageBundle(String language) throws IOException { table = new HashMap<>(); - // Also check to see if the user is working on localization, - // and has their own .properties files in their sketchbook. - // https://github.com/processing/processing4/wiki/Translations + // Disabling load from sketchbook in 4.2.1, because the path + // is not yet loaded from Preferences when languages are loaded. + // Fixing that (i.e. reloading languages) makes the code a lot + // more complicated for dubious benefit over simply editing the + // language files in the download (i.e. still would not help + // with adding new language codes.) String baseFilename = "languages/PDE.properties"; String langFilename = "languages/PDE_" + language + ".properties"; File baseFile = Base.getLibFile(baseFilename); + /* + // Also check to see if the user is working on localization, + // and has their own .properties files in their sketchbook. + // https://github.com/processing/processing4/wiki/Translations File userBaseFile = new File(Base.getSketchbookFolder(), baseFilename); if (userBaseFile.exists()) { baseFile = userBaseFile; } + */ File langFile = Base.getLibFile(langFilename); + /* File userLangFile = new File(Base.getSketchbookFolder(), langFilename); if (userLangFile.exists()) { langFile = userLangFile; } + */ read(baseFile); read(langFile); diff --git a/todo.txt b/todo.txt index 2051a70492..32b357b21d 100755 --- a/todo.txt +++ b/todo.txt @@ -1,8 +1,9 @@ 1293 (4.2.1) -_ ' appearing in code with Copy as HTML -_ Cannot load any user language files for i18n -_ https://github.com/processing/processing4/issues/722 - +o ' appearing in code with Copy as HTML +X could not reproduce +/ Cannot load any user language files for i18n +X https://github.com/processing/processing4/issues/722 +X not possible to load, updated the docs instead contribs X Syntax error highlighting placement / width incorrect from @sampottinger @@ -26,6 +27,8 @@ X https://github.com/processing/processing4/pull/745 X Debugger lists immediate array dimension last from @WillRabois04 X https://github.com/processing/processing4/issues/606 X https://github.com/processing/processing4/pull/729 +_ Mode-breaking interface change causing regression in Problem +_ https://github.com/processing/processing4/issues/751 pending From dc852779123139edb7fa00551dbf2c6dc210f204 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 16 Jul 2023 16:17:07 -0400 Subject: [PATCH 15/26] a little cleaning --- todo.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/todo.txt b/todo.txt index 32b357b21d..c515cbc6ed 100755 --- a/todo.txt +++ b/todo.txt @@ -58,10 +58,11 @@ _ just says "Error during export" rather than something more useful about dele manager _ if contrib (library only?) folder name changes on update, old lib not removed -_ Updates requiring a reboot give the false impression that they failed (in the updates tab) +_ Updates requiring a reboot give the false impression that they failed (in updates tab) _ https://github.com/processing/processing4/issues/647 _ lots of folders remaining in 'old' for Modes -_ were these shut off during debug? need to be moving these to trash (maybe only on startup) +_ were these shut off during debug? +_ need to be moving these to trash (maybe only on startup) _ implement automatic updates? _ especially with fixes to updates on startup... @@ -73,6 +74,7 @@ _ currently just using .enabled.color because they weren't in ColorSet _ opening p5jsMode sketch with no local.properties throws an NPE _ PDE can't find any files that match the supported extensions +_ maybe related: https://github.com/processing/processing4/issues/719 _ export to IntelliJ? how tricky? _ just copy jars to /lib? From 33aab6d635e43defdc9e42d3f86ac6b31af4129d Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 16 Jul 2023 16:46:05 -0400 Subject: [PATCH 16/26] get "everything" to build again; also swap "11" with jdk.train var --- build/build.xml | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/build/build.xml b/build/build.xml index 5ad9325cbc..458fab1d1a 100644 --- a/build/build.xml +++ b/build/build.xml @@ -1500,18 +1500,18 @@ - + - + - + - + @@ -1534,32 +1534,24 @@ - - - + - + - + - @@ -1580,17 +1572,17 @@ - + - + - + From 0c5be4f926f7e7360164224911de7a7ab05cfee5 Mon Sep 17 00:00:00 2001 From: Sam Pottinger Date: Sun, 16 Jul 2023 18:20:40 -0700 Subject: [PATCH 17/26] Force same interface on Problem. --- app/src/processing/app/Problem.java | 54 ++--------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/app/src/processing/app/Problem.java b/app/src/processing/app/Problem.java index c5f633c678..778f4c5af1 100644 --- a/app/src/processing/app/Problem.java +++ b/app/src/processing/app/Problem.java @@ -28,21 +28,6 @@ */ public interface Problem { - /** - * Strategy converting line number in tab to character offset from tab start. - */ - public interface LineToTabOffsetGetter { - - /** - * Convert a line number to the number of characters past tab start. - * - * @param line The line number to convert. - * @return The number of characters past tab start where that line starts. - */ - public int get(int line); - - } - /** * Get if the problem is an error that prevented compilation. * @@ -81,29 +66,13 @@ public interface LineToTabOffsetGetter { */ public String getMessage(); - /** - * Get the exact character on which this problem starts in code tab relative. - * - * @return Number of characters past the start of the tab if known where the - * code associated with the Problem starts. Returns empty if not provided. - */ - public Optional getTabStartOffset(); - - /** - * Get the exact character on which this problem ends in code tab relative. - * - * @return Number of characters past the start of the tab if known where the - * code associated with the Problem ends. Returns empty if not provided. - */ - public Optional getTabStopOffset(); - /** * Get the exact character on which this problem starts in code line relative. * * @return Number of characters past the start of the line if known where the * code associated with the Problem starts. Returns empty if not provided. */ - public Optional getLineStartOffset(); + public Optional getStartOffset(); /** * Get the exact character on which this problem ends in code line relative. @@ -111,26 +80,7 @@ public interface LineToTabOffsetGetter { * @return Number of characters past the start of the line if known where the * code associated with the Problem ends. Returns empty if not provided. */ - public Optional getLineStopOffset(); + public Optional getStopOffset(); - /** - * Get the exact character on which this problem ends in code tab relative. - * - * @param strategy Strategy to convert line to tab start if needed. - * @return Number of characters past the start of the tab if known where the - * code associated with the Problem ends, using the provided conversion - * if needed. Returns line start if character position not given. - */ - public int computeTabStartOffset(LineToTabOffsetGetter strategy); - - /** - * Get the exact character on which this problem ends in code tab relative. - * - * @param strategy Strategy to convert line to tab start if needed. - * @return Number of characters past the start of the tab if known where the - * code associated with the Problem ends, using the provided conversion - * if needed. Returns line start if character position not given. - */ - public int computeTabStopOffset(LineToTabOffsetGetter strategy); } From 36e1cbd26d018812ace3aa25358232634abb825d Mon Sep 17 00:00:00 2001 From: Sam Pottinger Date: Sun, 16 Jul 2023 18:39:17 -0700 Subject: [PATCH 18/26] Compiling again but highlighting wrong. --- app/src/processing/app/Problem.java | 8 +-- .../app/syntax/PdeTextAreaPainter.java | 16 ++--- app/src/processing/app/ui/Editor.java | 23 ++++---- .../src/processing/mode/java/JavaProblem.java | 58 ++----------------- .../processing/mode/java/SyntaxProblem.java | 46 +++------------ .../processing/mode/java/lsp/PdeAdapter.java | 11 ++-- 6 files changed, 39 insertions(+), 123 deletions(-) diff --git a/app/src/processing/app/Problem.java b/app/src/processing/app/Problem.java index 778f4c5af1..6a0faf3805 100644 --- a/app/src/processing/app/Problem.java +++ b/app/src/processing/app/Problem.java @@ -70,17 +70,17 @@ public interface Problem { * Get the exact character on which this problem starts in code line relative. * * @return Number of characters past the start of the line if known where the - * code associated with the Problem starts. Returns empty if not provided. + * code associated with the Problem starts. */ - public Optional getStartOffset(); + public int getStartOffset(); /** * Get the exact character on which this problem ends in code line relative. * * @return Number of characters past the start of the line if known where the - * code associated with the Problem ends. Returns empty if not provided. + * code associated with the Problem ends. */ - public Optional getStopOffset(); + public int getStopOffset(); } diff --git a/app/src/processing/app/syntax/PdeTextAreaPainter.java b/app/src/processing/app/syntax/PdeTextAreaPainter.java index be0d5fdc80..ddd34af0e2 100644 --- a/app/src/processing/app/syntax/PdeTextAreaPainter.java +++ b/app/src/processing/app/syntax/PdeTextAreaPainter.java @@ -46,8 +46,6 @@ public class PdeTextAreaPainter extends TextAreaPainter { protected Color gutterTextInactiveColor; protected Color gutterHighlightColor; - private final Problem.LineToTabOffsetGetter lineToTabOffsetGetter; - public PdeTextAreaPainter(JEditTextArea textArea, TextAreaDefaults defaults) { super(textArea, defaults); @@ -78,10 +76,6 @@ public void mousePressed(MouseEvent event) { } } }); - - lineToTabOffsetGetter = (x) -> { - return textArea.getLineStartOffset(x); - }; } @@ -153,12 +147,12 @@ protected void paintLine(Graphics gfx, int line, int x, TokenMarkerState marker) protected void paintErrorLine(Graphics gfx, int line, int x) { List problems = getEditor().findProblems(line); for (Problem problem : problems) { - int startOffset = problem.computeTabStartOffset(lineToTabOffsetGetter); - int stopOffset = problem.computeTabStopOffset(lineToTabOffsetGetter); - int lineOffsetStart = textArea.getLineStartOffset(line); int lineOffsetStop = textArea.getLineStopOffset(line); + int startOffset = lineOffsetStart + problem.getStartOffset(); + int stopOffset = lineOffsetStart + problem.getStopOffset(); + int wiggleStart = Math.max(startOffset, lineOffsetStart); int wiggleStop = Math.min(stopOffset, lineOffsetStop); @@ -338,8 +332,8 @@ public String getToolTipText(MouseEvent event) { int lineStart = textArea.getLineStartOffset(line); int lineEnd = textArea.getLineStopOffset(line); - int errorStart = problem.computeTabStartOffset(lineToTabOffsetGetter); - int errorEnd = problem.computeTabStopOffset(lineToTabOffsetGetter) + 1; + int errorStart = lineStart + problem.getStartOffset(); + int errorEnd = lineStart + problem.getStopOffset(); int startOffset = Math.max(errorStart, lineStart) - lineStart; int stopOffset = Math.min(errorEnd, lineEnd) - lineStart; diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index 824f8ac20a..d81ffdc2a4 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -2556,16 +2556,16 @@ public void updateErrorTable(List problems) { public void highlight(Problem p) { - Problem.LineToTabOffsetGetter getter = (x) -> { - return textarea.getLineStartOffset(x); - }; - - if (p != null) { - int tabIndex = p.getTabIndex(); - int tabToStartOffset = p.computeTabStartOffset(getter); - int tabToStopOffset = p.computeTabStopOffset(getter); - highlight(tabIndex, tabToStartOffset, tabToStopOffset); + if (p == null) { + return; } + + int tabIndex = p.getTabIndex(); + int lineNumber = p.getLineNumber(); + int lineStart = textarea.getLineStartOffset(lineNumber); + int tabToStartOffset = lineStart + p.getStartOffset(); + int tabToStopOffset = lineStart + p.getStopOffset(); + highlight(tabIndex, tabToStartOffset, tabToStopOffset); } @@ -2630,9 +2630,8 @@ public List findProblems(int line) { .filter(p -> p.getTabIndex() == currentTab) .filter(p -> { int pStartLine = p.getLineNumber(); - int pEndOffset = p.computeTabStopOffset( - (startLine) -> textarea.getLineStartOffset(pStartLine) - ); + int lineOffset = textarea.getLineOfOffset(pStartLine); + int pEndOffset = lineOffset + p.getStopOffset(); int pEndLine = textarea.getLineOfOffset(pEndOffset); return line >= pStartLine && line <= pEndLine; diff --git a/java/src/processing/mode/java/JavaProblem.java b/java/src/processing/mode/java/JavaProblem.java index 5233c785cb..5de937a09f 100644 --- a/java/src/processing/mode/java/JavaProblem.java +++ b/java/src/processing/mode/java/JavaProblem.java @@ -20,8 +20,6 @@ package processing.mode.java; -import java.util.Optional; - import org.eclipse.jdt.core.compiler.IProblem; import processing.app.Problem; @@ -44,9 +42,9 @@ public class JavaProblem implements Problem { /** Line number (pde code) of the error */ private final int lineNumber; - private Optional startOffset; + private int startOffset; - private Optional stopOffset; + private int stopOffset; /** * If the error is a 'cannot find type' contains the list of suggested imports @@ -62,8 +60,6 @@ public JavaProblem(String message, int type, int tabIndex, int lineNumber) { this.type = type; this.tabIndex = tabIndex; this.lineNumber = lineNumber; - this.startOffset = Optional.empty(); - this.stopOffset = Optional.empty(); } @@ -87,32 +83,22 @@ static public JavaProblem fromIProblem(IProblem iProblem, int tabIndex, public void setPDEOffsets(int startOffset, int stopOffset){ - this.startOffset = Optional.of(startOffset); - this.stopOffset = Optional.of(stopOffset); + this.startOffset = startOffset; + this.stopOffset = stopOffset; } @Override - public Optional getTabStartOffset() { + public int getStartOffset() { return startOffset; } @Override - public Optional getTabStopOffset() { + public int getStopOffset() { return stopOffset; } - @Override - public Optional getLineStartOffset() { - return Optional.empty(); - } - - @Override - public Optional getLineStopOffset() { - return Optional.empty(); - } - @Override public boolean isError() { return type == ERROR; @@ -163,36 +149,4 @@ public String toString() { + message; } - @Override - public int computeTabStartOffset(LineToTabOffsetGetter strategy) { - Optional nativeTabStartOffset = getTabStartOffset(); - if (nativeTabStartOffset.isPresent()) { - return nativeTabStartOffset.get(); - } - - Optional lineStartOffset = getLineStartOffset(); - int lineOffset = strategy.get(getLineNumber()); - if (lineStartOffset.isPresent()) { - return lineOffset + lineStartOffset.get(); - } else { - return lineOffset; - } - } - - @Override - public int computeTabStopOffset(LineToTabOffsetGetter strategy) { - Optional nativeTabStopOffset = getTabStopOffset(); - if (nativeTabStopOffset.isPresent()) { - return nativeTabStopOffset.get(); - } - - Optional lineStopOffset = getLineStopOffset(); - int lineOffset = strategy.get(getLineNumber()); - if (lineStopOffset.isPresent()) { - return lineOffset + lineStopOffset.get(); - } else { - return lineOffset; - } - } - } diff --git a/java/src/processing/mode/java/SyntaxProblem.java b/java/src/processing/mode/java/SyntaxProblem.java index bf037b9717..e549c7561a 100644 --- a/java/src/processing/mode/java/SyntaxProblem.java +++ b/java/src/processing/mode/java/SyntaxProblem.java @@ -29,10 +29,8 @@ public class SyntaxProblem extends JavaProblem { private final int tabIndex; private final int lineNumber; private final String message; - private final Optional tabStartOffset; - private final Optional tabStopOffset; - private final Optional lineStartOffset; - private final Optional lineStopOffset; + private final int lineStartOffset; + private final int lineStopOffset; /** * Create a new syntax problem. @@ -40,33 +38,19 @@ public class SyntaxProblem extends JavaProblem { * @param newTabIndex The tab number containing the source with the syntax issue. * @param newLineNumber The line number within the tab at which the offending code can be found. * @param newMessage Human readable message describing the issue. - * @param newStartOffset The character index at which the issue starts. This is relative to start - * of tab / file not relative to start of line if newUsesLineOffset is true else it is line - * offset. - * @param newStopOffset The character index at which the issue ends. This is relative to start - * of tab / file not relative to start of line if newUsesLineOffset is true else it is line - * offset. + * @param newStartOffset The character index at which the issue starts relative to line. + * @param newStopOffset The character index at which the issue end relative to line. */ public SyntaxProblem(int newTabIndex, int newLineNumber, String newMessage, int newStartOffset, - int newStopOffset, boolean newUsesLineOffset) { + int newStopOffset) { super(newMessage, JavaProblem.ERROR, newLineNumber, newLineNumber); tabIndex = newTabIndex; lineNumber = newLineNumber; message = newMessage; - - if (newUsesLineOffset) { - lineStartOffset = Optional.of(newStartOffset); - lineStopOffset = Optional.of(newStopOffset); - tabStartOffset = Optional.empty(); - tabStopOffset = Optional.empty(); - } else { - lineStartOffset = Optional.empty(); - lineStopOffset = Optional.empty(); - tabStartOffset = Optional.of(newStartOffset); - tabStopOffset = Optional.of(newStopOffset); - } + lineStartOffset = newStartOffset; + lineStopOffset = newStopOffset; } @Override @@ -94,23 +78,11 @@ public String getMessage() { return message; } - @Override - public Optional getTabStartOffset() { - return tabStartOffset; - } - - @Override - public Optional getTabStopOffset() { - return tabStopOffset; - } - - @Override - public Optional getLineStartOffset() { + public int getStartOffset() { return lineStartOffset; } - @Override - public Optional getLineStopOffset() { + public int getStopOffset() { return lineStopOffset; } diff --git a/java/src/processing/mode/java/lsp/PdeAdapter.java b/java/src/processing/mode/java/lsp/PdeAdapter.java index 83d2b30960..1a58f3c8ed 100644 --- a/java/src/processing/mode/java/lsp/PdeAdapter.java +++ b/java/src/processing/mode/java/lsp/PdeAdapter.java @@ -229,24 +229,21 @@ void updateProblems(List problems) { .map(prob -> { SketchCode code = sketch.getCode(prob.getTabIndex()); - Optional startOffset = prob.getTabStartOffset(); - Optional endOffset = prob.getTabStopOffset(); - - assert startOffset.isPresent(); - assert endOffset.isPresent(); + int startOffset = prob.getStartOffset(); + int endOffset = prob.getStopOffset(); Diagnostic dia = new Diagnostic( new Range( new Position( prob.getLineNumber(), PdeAdapter - .toLineCol(code.getProgram(), startOffset.get()) + .toLineCol(code.getProgram(), startOffset) .col - 1 ), new Position( prob.getLineNumber(), PdeAdapter - .toLineCol(code.getProgram(), endOffset.get()) + .toLineCol(code.getProgram(), endOffset) .col - 1 ) ), From d366df99ccb2e629787d52d641d48751025653e8 Mon Sep 17 00:00:00 2001 From: Sam Pottinger Date: Sun, 16 Jul 2023 18:51:07 -0700 Subject: [PATCH 19/26] Hold on fix for #752. --- app/src/processing/app/syntax/PdeTextAreaPainter.java | 4 +++- java/src/processing/mode/java/ProblemFactory.java | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/processing/app/syntax/PdeTextAreaPainter.java b/app/src/processing/app/syntax/PdeTextAreaPainter.java index ddd34af0e2..b49875ab29 100644 --- a/app/src/processing/app/syntax/PdeTextAreaPainter.java +++ b/app/src/processing/app/syntax/PdeTextAreaPainter.java @@ -326,7 +326,7 @@ static private void paintSquiggle(Graphics g, int y, int x1, int x2) { public String getToolTipText(MouseEvent event) { fontMetrics = getFontMetrics(); int line = event.getY() / fontMetrics.getHeight() + textArea.getFirstLine(); - if (line >= 0 || line < textArea.getLineCount()) { + if (line >= 0 || line < textArea.getLineCount()) {getPreprocessIssues List problems = getEditor().findProblems(line); for (Problem problem : problems) { int lineStart = textArea.getLineStartOffset(line); @@ -338,6 +338,8 @@ public String getToolTipText(MouseEvent event) { int startOffset = Math.max(errorStart, lineStart) - lineStart; int stopOffset = Math.min(errorEnd, lineEnd) - lineStart; + System.out.println(lineStart + "\t" + lineEnd + "\t" + errorStart + "\t" + errorEnd + "\t" + startOffset + "\t" + stopOffset); + int x = event.getX(); if (x >= textArea.offsetToX(line, startOffset) && diff --git a/java/src/processing/mode/java/ProblemFactory.java b/java/src/processing/mode/java/ProblemFactory.java index ce5cbff63a..ac93afd862 100644 --- a/java/src/processing/mode/java/ProblemFactory.java +++ b/java/src/processing/mode/java/ProblemFactory.java @@ -52,9 +52,8 @@ public static Problem build(PdePreprocessIssue pdePreprocessIssue, List tab, localLine, message, - lineStart, - lineStop, - false + 0, + lineStop - lineStart ); } @@ -85,8 +84,7 @@ public static Problem build(PdePreprocessIssue pdePreprocessIssue, List localLine, message, 0, - col, - true + col ); } From c2356b834d8546b0bb03b755ad2c61ab4b216d5e Mon Sep 17 00:00:00 2001 From: Sam Pottinger Date: Sun, 16 Jul 2023 19:17:59 -0700 Subject: [PATCH 20/26] Simple PDE test working again. --- .../app/syntax/PdeTextAreaPainter.java | 5 ++-- app/src/processing/app/ui/Editor.java | 3 +- java/src/processing/mode/java/JavaEditor.java | 2 +- .../processing/mode/java/PreprocService.java | 29 +++++++++++++++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/src/processing/app/syntax/PdeTextAreaPainter.java b/app/src/processing/app/syntax/PdeTextAreaPainter.java index b49875ab29..b63fa56744 100644 --- a/app/src/processing/app/syntax/PdeTextAreaPainter.java +++ b/app/src/processing/app/syntax/PdeTextAreaPainter.java @@ -147,6 +147,7 @@ protected void paintLine(Graphics gfx, int line, int x, TokenMarkerState marker) protected void paintErrorLine(Graphics gfx, int line, int x) { List problems = getEditor().findProblems(line); for (Problem problem : problems) { + System.out.println("here"); int lineOffsetStart = textArea.getLineStartOffset(line); int lineOffsetStop = textArea.getLineStopOffset(line); @@ -326,7 +327,7 @@ static private void paintSquiggle(Graphics g, int y, int x1, int x2) { public String getToolTipText(MouseEvent event) { fontMetrics = getFontMetrics(); int line = event.getY() / fontMetrics.getHeight() + textArea.getFirstLine(); - if (line >= 0 || line < textArea.getLineCount()) {getPreprocessIssues + if (line >= 0 || line < textArea.getLineCount()) { List problems = getEditor().findProblems(line); for (Problem problem : problems) { int lineStart = textArea.getLineStartOffset(line); @@ -338,8 +339,6 @@ public String getToolTipText(MouseEvent event) { int startOffset = Math.max(errorStart, lineStart) - lineStart; int stopOffset = Math.min(errorEnd, lineEnd) - lineStart; - System.out.println(lineStart + "\t" + lineEnd + "\t" + errorStart + "\t" + errorEnd + "\t" + startOffset + "\t" + stopOffset); - int x = event.getX(); if (x >= textArea.offsetToX(line, startOffset) && diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index d81ffdc2a4..a7e5885858 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -2630,10 +2630,11 @@ public List findProblems(int line) { .filter(p -> p.getTabIndex() == currentTab) .filter(p -> { int pStartLine = p.getLineNumber(); - int lineOffset = textarea.getLineOfOffset(pStartLine); + int lineOffset = textarea.getLineStartOffset(pStartLine); int pEndOffset = lineOffset + p.getStopOffset(); int pEndLine = textarea.getLineOfOffset(pEndOffset); + System.out.println(line + "\t" + pStartLine + "\t" + pEndLine); return line >= pStartLine && line <= pEndLine; }) .collect(Collectors.toList()); diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index 338a6bd298..198c1150c5 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -118,7 +118,7 @@ protected JavaEditor(Base base, String path, EditorState state, // setting breakpoints will flag sketch as modified, so override this here getSketch().setModified(false); - preprocService = new PreprocService(this.jmode, this.sketch); + preprocService = new PreprocService(this.jmode, this.sketch, this); // long t5 = System.currentTimeMillis(); diff --git a/java/src/processing/mode/java/PreprocService.java b/java/src/processing/mode/java/PreprocService.java index 8557f6f398..3d59032b69 100644 --- a/java/src/processing/mode/java/PreprocService.java +++ b/java/src/processing/mode/java/PreprocService.java @@ -93,13 +93,15 @@ public class PreprocService { private volatile boolean running; private CompletableFuture preprocessingTask = new CompletableFuture<>(); + private JavaEditor editor; + private CompletableFuture lastCallback = new CompletableFuture<>() {{ complete(null); // initialization block }}; /** - * Create a new preprocessing service to support an editor. + * Create a new preprocessing service to support the language server. */ public PreprocService(JavaMode javaMode, Sketch sketch) { this.javaMode = javaMode; @@ -112,6 +114,21 @@ public PreprocService(JavaMode javaMode, Sketch sketch) { preprocessingThread.start(); } + /** + * Create a new preprocessing service to support an editor. + */ + public PreprocService(JavaMode javaMode, Sketch sketch, JavaEditor editor) { + this.javaMode = javaMode; + this.sketch = sketch; + this.editor = editor; + + // Register listeners for first run + whenDone(this::fireListeners); + + preprocessingThread = new Thread(this::mainLoop, "ECS"); + preprocessingThread.start(); + } + /** * The "main loop" for the background thread that checks for code issues. */ @@ -411,10 +428,18 @@ private PreprocSketch preprocessSketch(PreprocSketch prevResult) { throw new RuntimeException("Unexpected sketch exception in preprocessing: " + e); } + final int endNumLines = numLines; + if (preprocessorResult.getPreprocessIssues().size() > 0) { - preprocessorResult.getPreprocessIssues().stream() + if (editor == null) { + preprocessorResult.getPreprocessIssues().stream() .map((x) -> ProblemFactory.build(x, tabLineStarts)) .forEach(result.otherProblems::add); + } else { + preprocessorResult.getPreprocessIssues().stream() + .map((x) -> ProblemFactory.build(x, tabLineStarts, endNumLines, editor)) + .forEach(result.otherProblems::add); + } result.hasSyntaxErrors = true; } From 8059c7bcc89516d210526c4b6f1d97c71ecdc5e6 Mon Sep 17 00:00:00 2001 From: Sam Pottinger Date: Sun, 16 Jul 2023 19:49:46 -0700 Subject: [PATCH 21/26] Working JavaError again without full highlight. --- app/src/processing/app/syntax/PdeTextAreaPainter.java | 8 ++------ app/src/processing/app/ui/Editor.java | 3 +-- java/src/processing/mode/java/ErrorChecker.java | 4 +--- java/src/processing/mode/java/JavaProblem.java | 4 ++++ 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/src/processing/app/syntax/PdeTextAreaPainter.java b/app/src/processing/app/syntax/PdeTextAreaPainter.java index b63fa56744..2c83a518b7 100644 --- a/app/src/processing/app/syntax/PdeTextAreaPainter.java +++ b/app/src/processing/app/syntax/PdeTextAreaPainter.java @@ -147,15 +147,11 @@ protected void paintLine(Graphics gfx, int line, int x, TokenMarkerState marker) protected void paintErrorLine(Graphics gfx, int line, int x) { List problems = getEditor().findProblems(line); for (Problem problem : problems) { - System.out.println("here"); int lineOffsetStart = textArea.getLineStartOffset(line); int lineOffsetStop = textArea.getLineStopOffset(line); - int startOffset = lineOffsetStart + problem.getStartOffset(); - int stopOffset = lineOffsetStart + problem.getStopOffset(); - - int wiggleStart = Math.max(startOffset, lineOffsetStart); - int wiggleStop = Math.min(stopOffset, lineOffsetStop); + int wiggleStart = lineOffsetStart + problem.getStartOffset(); + int wiggleStop = lineOffsetStart + problem.getStopOffset(); int y = textArea.lineToY(line) + getLineDisplacement(); diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index a7e5885858..911df7a499 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -2633,8 +2633,7 @@ public List findProblems(int line) { int lineOffset = textarea.getLineStartOffset(pStartLine); int pEndOffset = lineOffset + p.getStopOffset(); int pEndLine = textarea.getLineOfOffset(pEndOffset); - - System.out.println(line + "\t" + pStartLine + "\t" + pEndLine); + return line >= pStartLine && line <= pEndLine; }) .collect(Collectors.toList()); diff --git a/java/src/processing/mode/java/ErrorChecker.java b/java/src/processing/mode/java/ErrorChecker.java index 1302dd773a..24cf520e99 100644 --- a/java/src/processing/mode/java/ErrorChecker.java +++ b/java/src/processing/mode/java/ErrorChecker.java @@ -199,7 +199,7 @@ static private JavaProblem convertIProblem(IProblem iproblem, PreprocSketch ps) String badCode = ps.getPdeCode(in); int line = ps.tabOffsetToTabLine(in.tabIndex, in.startTabOffset); JavaProblem p = JavaProblem.fromIProblem(iproblem, in.tabIndex, line, badCode); - p.setPDEOffsets(in.startTabOffset, in.stopTabOffset); + p.setPDEOffsets(0, 1); // TODO return p; } return null; @@ -252,7 +252,6 @@ static private List checkForCurlyQuotes(PreprocSketch ps) { String message = Language.interpolate("editor.status.bad_curly_quote", q); JavaProblem problem = new JavaProblem(message, JavaProblem.ERROR, tabIndex, tabLine); - problem.setPDEOffsets(tabOffset, tabOffset+1); problems.add(problem); } @@ -294,7 +293,6 @@ static private List checkForCurlyQuotes(PreprocSketch ps) { message = Language.interpolate("editor.status.bad_curly_quote", q); } JavaProblem p = new JavaProblem(message, JavaProblem.ERROR, in.tabIndex, line); - p.setPDEOffsets(tabStart, tabStop); problems2.add(p); } } diff --git a/java/src/processing/mode/java/JavaProblem.java b/java/src/processing/mode/java/JavaProblem.java index 5de937a09f..005b483807 100644 --- a/java/src/processing/mode/java/JavaProblem.java +++ b/java/src/processing/mode/java/JavaProblem.java @@ -60,6 +60,10 @@ public JavaProblem(String message, int type, int tabIndex, int lineNumber) { this.type = type; this.tabIndex = tabIndex; this.lineNumber = lineNumber; + + // Default to 0, 1 unless a longer section is specified + this.startOffset = 0; + this.stopOffset = 1; } From aa80f30eb5847152d212aecf8495fa28a14bf0b0 Mon Sep 17 00:00:00 2001 From: Sam Pottinger Date: Sun, 16 Jul 2023 19:51:20 -0700 Subject: [PATCH 22/26] IProblem bounds resolved. --- java/src/processing/mode/java/ErrorChecker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/src/processing/mode/java/ErrorChecker.java b/java/src/processing/mode/java/ErrorChecker.java index 24cf520e99..e631fbd4f2 100644 --- a/java/src/processing/mode/java/ErrorChecker.java +++ b/java/src/processing/mode/java/ErrorChecker.java @@ -199,7 +199,7 @@ static private JavaProblem convertIProblem(IProblem iproblem, PreprocSketch ps) String badCode = ps.getPdeCode(in); int line = ps.tabOffsetToTabLine(in.tabIndex, in.startTabOffset); JavaProblem p = JavaProblem.fromIProblem(iproblem, in.tabIndex, line, badCode); - p.setPDEOffsets(0, 1); // TODO + p.setPDEOffsets(0, iproblem.getSourceEnd() - iproblem.getSourceStart()); return p; } return null; From d2262f912d06bb0acd6bf398e44fec42441be47d Mon Sep 17 00:00:00 2001 From: Sam Pottinger Date: Sun, 16 Jul 2023 19:56:45 -0700 Subject: [PATCH 23/26] Clean up for #752. --- java/src/processing/mode/java/JavaEditor.java | 2 +- .../processing/mode/java/PreprocService.java | 29 ++----------- .../processing/mode/java/ProblemFactory.java | 43 ------------------- 3 files changed, 4 insertions(+), 70 deletions(-) diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index 198c1150c5..338a6bd298 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -118,7 +118,7 @@ protected JavaEditor(Base base, String path, EditorState state, // setting breakpoints will flag sketch as modified, so override this here getSketch().setModified(false); - preprocService = new PreprocService(this.jmode, this.sketch, this); + preprocService = new PreprocService(this.jmode, this.sketch); // long t5 = System.currentTimeMillis(); diff --git a/java/src/processing/mode/java/PreprocService.java b/java/src/processing/mode/java/PreprocService.java index 3d59032b69..718728d415 100644 --- a/java/src/processing/mode/java/PreprocService.java +++ b/java/src/processing/mode/java/PreprocService.java @@ -93,8 +93,6 @@ public class PreprocService { private volatile boolean running; private CompletableFuture preprocessingTask = new CompletableFuture<>(); - private JavaEditor editor; - private CompletableFuture lastCallback = new CompletableFuture<>() {{ complete(null); // initialization block @@ -114,21 +112,6 @@ public PreprocService(JavaMode javaMode, Sketch sketch) { preprocessingThread.start(); } - /** - * Create a new preprocessing service to support an editor. - */ - public PreprocService(JavaMode javaMode, Sketch sketch, JavaEditor editor) { - this.javaMode = javaMode; - this.sketch = sketch; - this.editor = editor; - - // Register listeners for first run - whenDone(this::fireListeners); - - preprocessingThread = new Thread(this::mainLoop, "ECS"); - preprocessingThread.start(); - } - /** * The "main loop" for the background thread that checks for code issues. */ @@ -431,15 +414,9 @@ private PreprocSketch preprocessSketch(PreprocSketch prevResult) { final int endNumLines = numLines; if (preprocessorResult.getPreprocessIssues().size() > 0) { - if (editor == null) { - preprocessorResult.getPreprocessIssues().stream() - .map((x) -> ProblemFactory.build(x, tabLineStarts)) - .forEach(result.otherProblems::add); - } else { - preprocessorResult.getPreprocessIssues().stream() - .map((x) -> ProblemFactory.build(x, tabLineStarts, endNumLines, editor)) - .forEach(result.otherProblems::add); - } + preprocessorResult.getPreprocessIssues().stream() + .map((x) -> ProblemFactory.build(x, tabLineStarts)) + .forEach(result.otherProblems::add); result.hasSyntaxErrors = true; } diff --git a/java/src/processing/mode/java/ProblemFactory.java b/java/src/processing/mode/java/ProblemFactory.java index ac93afd862..fd038a0a81 100644 --- a/java/src/processing/mode/java/ProblemFactory.java +++ b/java/src/processing/mode/java/ProblemFactory.java @@ -14,49 +14,6 @@ */ public class ProblemFactory { - /** - * Create a new {Problem}. - * - * @param pdePreprocessIssue The preprocess issue found. - * @param tabStarts The list of line numbers on which each tab starts. - * @param editor The editor in which errors will appear. - * @return Newly created problem. - */ - public static Problem build(PdePreprocessIssue pdePreprocessIssue, List tabStarts, - int numLines, Editor editor) { - - int line = pdePreprocessIssue.getLine(); - - // Sometimes errors are reported one line past end of sketch. Fix that. - if (line >= numLines) { - line = numLines - 1; - } - - // Get local area - TabLine tabLine = getTab(tabStarts, line); - - int tab = tabLine.getTab(); - int localLine = tabLine.getLineInTab(); // Problems emitted in 0 index - - // Generate syntax problem - String message = pdePreprocessIssue.getMsg(); - - int lineStart = editor.getLineStartOffset(localLine); - int lineStop = editor.getLineStopOffset(localLine) - 1; - - if (lineStart == lineStop) { - lineStop++; - } - - return new SyntaxProblem( - tab, - localLine, - message, - 0, - lineStop - lineStart - ); - } - /** * Create a new {Problem}. * From 789c644e265a2105e0987a50b3036d4267bc6ea4 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Mon, 17 Jul 2023 07:41:09 -0400 Subject: [PATCH 24/26] note fixes from Sam --- todo.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/todo.txt b/todo.txt index c515cbc6ed..6ebf6b16f8 100755 --- a/todo.txt +++ b/todo.txt @@ -9,6 +9,9 @@ contribs X Syntax error highlighting placement / width incorrect from @sampottinger X https://github.com/processing/processing4/issues/714 X https://github.com/processing/processing4/pull/715 +X Mode-breaking interface change causing regression in Problem +X https://github.com/processing/processing4/issues/751 +X https://github.com/processing/processing4/pull/752 X Tweak mode issue with hex codes including transparency from @sampottinger X https://github.com/processing/processing4/issues/720 X https://github.com/processing/processing4/pull/721 @@ -27,8 +30,6 @@ X https://github.com/processing/processing4/pull/745 X Debugger lists immediate array dimension last from @WillRabois04 X https://github.com/processing/processing4/issues/606 X https://github.com/processing/processing4/pull/729 -_ Mode-breaking interface change causing regression in Problem -_ https://github.com/processing/processing4/issues/751 pending From b1b8d3b4548098354829c2dcc1f2b89f639c26a9 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Tue, 18 Jul 2023 07:41:58 -0400 Subject: [PATCH 25/26] todo notes and inherit dark/light settings from macOS (#699) --- build/build.xml | 2 ++ todo.txt | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/build/build.xml b/build/build.xml index 458fab1d1a..dc988d5668 100644 --- a/build/build.xml +++ b/build/build.xml @@ -611,6 +611,8 @@