Author Topic: AutoLISP Editor in 2024  (Read 2994 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: AutoLISP Editor in 2024
« Reply #45 on: March 05, 2024, 12:21:24 PM »
Did you install the extension to VSCode?

File -> Preferences -> Extensions ---> Search for "AutoLisp"
Load the: "AutoCAD AutoLISP Extension"
I figured it out. You have to have a debug session running, i.e. F5. This is counterintuitive, as I just wanted to load the selected lisp, not the whole form, which F5 does.

It is not counterintuitive at all. VSCode is a totally different process, you need to instruct it to "attach to autocad's process" in order to send information to it (and get information back). Not sure if you've ever heard of the client-server model for programs but that's what using VSCode is.

However, the fact that VSCode will send the entire files contents upon establishing the "connection" is annoying (what Kdub said earlier).
When I do this in POSIX C I use a named pipe [file], this is probably the same on Windows but I'd guess that when VSCode makes the connection it dumps the current files contents to the named pipe instead of just opening the pipe. This is a bit deep but I guess, I offer up the above gibberish to hopefully shed some light on what is happening in the background (10,000 foot overview).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

57gmc

  • Bull Frog
  • Posts: 366
Re: AutoLISP Editor in 2024
« Reply #46 on: March 05, 2024, 12:27:30 PM »
"Counterintuitive" was probably not the right word. It's just that it was not documented I guess and up to you to figure it out. Yeah it's too bad that you can't just attach to acad without loading all the code in your lisp file. If you have a bug in it, you might want to test a piece at a time.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: AutoLISP Editor in 2024
« Reply #47 on: March 05, 2024, 12:45:04 PM »
I guess, if we were coding this connection we would have made: "attach", "load", and "connect" but...*meh*

"Not documented" is the mantra for most Windows developers. Here's a spotlight, do you have documentation/comments for/in your code?! :) :p

But seriously, if you take a look at some good coders, they typically have the good habit of documenting their code.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

57gmc

  • Bull Frog
  • Posts: 366
Re: AutoLISP Editor in 2024
« Reply #48 on: March 05, 2024, 01:29:17 PM »
I can't seem to get any hover tips working for autolisp in VSCode.
Do you have a specific plugin that finds the function headers to display them as a tip?
I'm not getting the inline comment to work either. The hover tip says <undocumented>

One problem I'm having is that I'm trying to change the comments for Lee's LM:GetAttributeValues function. Here's what I have.
Code - Auto/Visual Lisp: [Select]
  1. ;/
  2.     Get Attribute Values  -  Lee Mac
  3.     Returns an association list of attributes present in the supplied block.
  4.     @Param blk <[ent] Block (Insert) Entity Name>
  5.     @Returns <[lst] Association list of ((<tag> . <value>) ... )>
  6. /;
  7.  
VS isn't reading the whole thing as an inline comment. It highlights list and Insert and tries to evaluate them.
« Last Edit: March 05, 2024, 01:55:25 PM by 57gmc »

57gmc

  • Bull Frog
  • Posts: 366
Re: AutoLISP Editor in 2024
« Reply #49 on: March 05, 2024, 01:35:11 PM »
I guess, if we were coding this connection we would have made: "attach", "load", and "connect" but...*meh*

"Not documented" is the mantra for most Windows developers. Here's a spotlight, do you have documentation/comments for/in your code?! :) :p

But seriously, if you take a look at some good coders, they typically have the good habit of documenting their code.
Yes, I try to comment all my code. I got started when I found out about C#'s xml export of comments. Now, I'm trying to implement the lisp comment you showed, but can't find any documentation on the format. All I can find is the use of ;;;. I found some mention of ;/ /; but not how to format it for VS comments.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: AutoLISP Editor in 2024
« Reply #50 on: March 05, 2024, 01:41:57 PM »
Try double-clicking a function name, then right-click and choose "Generate Documentation" (which should just place a header above your function that looks like the one I provided). Save the file too (maybe)? I don't think I did anything special (I don't really use VSCode myself so mine is pretty stock, but I may start using it more now; some of these features are pretty cool).

BTW, my files will start to look like this now.
Code - Auto/Visual Lisp: [Select]
  1. ;;; ------------------------------------------------------x- LSP -x----
  2. ;;; FOUR.LSP
  3. ;;; A program that will change the world!
  4. ;;;
  5. ;;; HISTORY
  6. ;;;     version 1.0 - Mar 05 2024
  7. ;;; -------------------------------------------------------------------
  8.  
  9. ;;;;
  10. ;; unit testing framework.
  11. (setq DEBUG nil)                                        ; -True  = debugging mode.
  12.                                                         ;  False = regular mode. (default)
  13.   (DEBUG
  14.     ;|
  15.       Asserts an expression is equal to an expected result.
  16.       @param result an expression to run.
  17.       @param expected a result to check equality to.
  18.       @returns boole (`T` or `nil`)
  19.     |;
  20.     (defun #assert (result expected)
  21.          (lambda ( result expected )
  22.            (equal (eval result) expected)))
  23.     (defun *error* (msg) (vl-bt))
  24.     )
  25.   (T (set '#assert nil) (set '*error* nil))
  26.   )
  27.  
  28. ;;;;
  29. ;; Support procedures
  30.  
  31. ;|
  32.   Returns the number 4.
  33.   @param `nil`
  34.   @returns `4`
  35. |;
  36. (defun c:four () (+ 2 2))
  37.  
  38. ;|
  39.   Squares a number
  40.   @Param nu number
  41.   @Returns `nu`^2
  42. |;
  43. (defun square (nu)
  44.   (* nu nu))
  45.  
  46. ;|
  47.   cubes a number
  48.   @Param x number
  49.   @Returns `x`^3
  50. |;
  51. (defun cube (x)
  52.   (* x x x))
  53.  
  54.  
  55. ;;;;
  56. ;; Testing.
  57.  
  58.   (DEBUG
  59.     (#assert '(/ 2 0) 0)                                ; -Assert we can divide by zero.
  60.     (#assert '(+ 2 2) 4)                                ; -Assert 2+2 = 4.
  61.     (#assert '(c:four) 4)                               ; -Assert `four` returns 4.
  62.     )
  63.   )
  64.  
  65. ;;;;
  66. ;; main code
  67.  
  68. (c:four)                                                ; -Call our main procedure to change the world.
  69.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: AutoLISP Editor in 2024
« Reply #51 on: March 05, 2024, 01:50:01 PM »
Oh?! VSCode has folds too!
If you highlight a bunch of code, right click and choose "insert region" you get this:

Code - Auto/Visual Lisp: [Select]
  1. ;#region unit testing
  2.   (DEBUG
  3.     (#assert '(/ 2 0) 0)                                ; -Assert we can devide by zero.
  4.     (#assert '(+ 2 2) 4)                                ; -Assert 2+2 = 4.
  5.     (#assert '(c:four) 4)                               ; -Assert `four` returns 4.
  6.     )
  7.   )
  8. ;#endregion

Check the gutter and you get a collapse feature.  But it looks like it will also hide any breakpoints collapsed in the region though (Come on MS, give me a symbol in the gutter that there is a hidden breakpoint in the collapsed region!).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

57gmc

  • Bull Frog
  • Posts: 366
Re: AutoLISP Editor in 2024
« Reply #52 on: March 05, 2024, 02:00:25 PM »
Try double-clicking a function name, then right-click and choose "Generate Documentation"
Aha! I did that and it used a vertical pipe, not a forward slash as shown in your example. At least that's what it looks like in the code window.

57gmc

  • Bull Frog
  • Posts: 366
Re: AutoLISP Editor in 2024
« Reply #53 on: March 05, 2024, 02:06:13 PM »
Oh?! VSCode has folds too!
Check the gutter and you get a collapse feature.  But it looks like it will also hide any breakpoints collapsed in the region though (Come on MS, give me a symbol in the gutter that there is a hidden breakpoint in the collapsed region!).
It works on all functions automatically too. Just hover to the left.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: AutoLISP Editor in 2024
« Reply #54 on: March 05, 2024, 06:23:23 PM »

BTW, my files will start to look like this now.

 >>>> snip

And I see that as a good thing for a goal.

but if I see any
;_ Function-Closing   comments in your code I'll find out where you live  :-)




Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: AutoLISP Editor in 2024
« Reply #55 on: March 05, 2024, 08:56:20 PM »
Wasn't the "official method" to use: ");_end <function>" but seeing as how I use the "other style" mostly that might make for some very interesting code!! :)

Code - Auto/Visual Lisp: [Select]
  1. (defun squareandcube (nu)
  2.   (* (* nu nu) nu);|_end multiply|; );|_end defun|;
...seems readable.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: AutoLISP Editor in 2024
« Reply #56 on: March 06, 2024, 12:00:31 AM »
So does
Code - Auto/Visual Lisp: [Select]
  1. (defun squareandcube (nu)
  2.   (* nu nu nu)
  3. )
  4.  
. .  :-D

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

keithsCADservices

  • Newt
  • Posts: 45
Re: AutoLISP Editor in 2024
« Reply #57 on: March 06, 2024, 10:33:29 PM »
"Counterintuitive" was probably not the right word. It's just that it was not documented I guess and up to you to figure it out. Yeah it's too bad that you can't just attach to acad without loading all the code in your lisp file. If you have a bug in it, you might want to test a piece at a time.

For what it's worth I found the documentation to be lacking as well. I was able to get acquainted with Visual Studio (the "big" more complex code editor) quicker than VS Code (for C# programming). That was probably one of the biggest factors in forming my conclusion: VS Code is supposed to be quick, light and easy.

keithsCADservices

  • Newt
  • Posts: 45
Re: AutoLISP Editor in 2024
« Reply #58 on: March 06, 2024, 10:56:47 PM »
If debugging is your only problem, you can use `vl-bt` to debug instead of using VLIDE:

Define a simple error handler with:
Code - Auto/Visual Lisp: [Select]
  1. (defun *error* (msg) (vl-bt))
or
Code - Auto/Visual Lisp: [Select]
  1. (set '*error* (lambda (msg) (vl-bt)))
Create your code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bug () (/ 2 0))
debug your code on the command line.
Code: [Select]
Backtrace:
[0.47] (VL-BT)
[1.43] (#<SUBR @00000158a9fa6278 -lambda-> "divide by zero")
[2.39] (_call-err-hook #<SUBR @00000158a9fa6278 -lambda-> "divide by zero")
[3.33] (sys-error "divide by zero")
:ERROR-BREAK.28 nil
[4.25] (/ 2 0)
[5.19] (C:BUG)
[6.15] (#<SUBR @00000158a9fa6548 -rts_top->)
[7.12] (#<SUBR @00000158b0659750 veval-str-body> "(C:BUG)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)

After your bugs are dead (-i.e. switch to production code), just (setq *error* nil) and/or replace/use your standard error handler.

All the info you're sharing has been immensely helpful. The lack of debugging was another big check in the "VS Code sucks" column for myself. Perhaps Autodesk should pay you to write a better userguide.

I was pretty miffed when I found out that you couldn't debug in AutoCAD LT. At that time they (Autodesk) had just copy-pasted the help docs from Full to LT which let me down a bit of a dead end. They've since fixed it at least. There's defintely work-arounds to make up for it... but for myself I've still had to spent $$$ on ACAD full to make sure I can code at full pace. I'm dying to ditch ACAD Full for either LT or something else.

57gmc

  • Bull Frog
  • Posts: 366
Re: AutoLISP Editor in 2024
« Reply #59 on: March 07, 2024, 10:33:17 AM »
"Counterintuitive" was probably not the right word. It's just that it was not documented I guess and up to you to figure it out. Yeah it's too bad that you can't just attach to acad without loading all the code in your lisp file. If you have a bug in it, you might want to test a piece at a time.

For what it's worth I found the documentation to be lacking as well. I was able to get acquainted with Visual Studio (the "big" more complex code editor) quicker than VS Code (for C# programming). That was probably one of the biggest factors in forming my conclusion: VS Code is supposed to be quick, light and easy.
I found an issue request on Github. This is a known problem since 2021. I posted a reminder that it's still broken and it was acknowledged. So maybe it will be available in a future release.