vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
547 stars 90 forks source link

[RFE] Run-time language reflection/introspection facilities #279

Closed Bob131 closed 2 years ago

Bob131 commented 2 years ago

Playing around with it, the Emacs asy-mode seems a little anaemic: comparable Emacs packages like python-mode or Geiser are able to interface with a running interpreter to provide lots of nice integrations (xref, eldoc, symbol completion, inline documentation, etc). However, the Asymptote language is missing the introspection facilities required to beef up asy-mode. I have some proposals:

Probably the most important part is being able to inspect the variable bindings of the current environment. I'm thinking a patch like the following should do the job. (diff 86954d8680ae6a6d3e416fa3a7dea56c97e39662)

diff --git a/runtime.in b/runtime.in
index 27cde400..3b0d98f9 100644
--- a/runtime.in
+++ b/runtime.in
@@ -782,6 +782,11 @@ void list(string *s, bool imports=false)
   r->e.list(imports ? 0 : r);
 }
 ^L
+Void toplist()
+{
+  Stack->getEnvironment()->e.list();
+}
+^L

 // Guide operations

This would enable greatly improved completion and would help a bit with eldoc. This particular implementation might be a little too blunt, though; someone with more familiarity with the Asymptote code base might want to adjust it to return a list of strings that can be manipulated by code running in the interpreter.

For everything else (xref, eldoc, etc), the heavy use of function overloading seems to present a challenge.

johncbowman commented 2 years ago

You can currently get this list with asy -l or asy -l examples/venn but I agree that an asy function like string[] global() returning a list of global functions and variables would be convenient.

johncbowman commented 2 years ago

For now I will close this issue until you have had a chance to try out the language server protocol now in the master branch and upcoming 2.71 release. It should provide some of the functionality you are looking for, along with a systematic framework for further development.