-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: new line indenting #52
Comments
I've been wanting to fix this for a while. I'll look into it again. There's an editor.formatOnType setting, but it's not working. I also don't know if it formats the entire document, which would be bad. |
I have a bit of free time coming up, and happy to work on that, or help @n00p3 with #54.
|
@mseddon If you want to take a crack at it, go for it. I think it'll be easier now that everything's server side. I don't think it'll require any changes on the client side. The formatting code now handles range formatting, so it should be possible to reuse that code to get the edits. |
I've looked into it a bit more. The formatOnType feature is apparently quite annoying. It's disabled by default and it looks like very few people turn it on because, well, it's annoying. The "right" solution is to use what they call "OnEnterRules". Unfortunately, where enter gets handled is not in async code so can't call the language server to do the work. It's regex based, which means it can't match parenthesis. There's an issue against vscode that's still open from 2019 about this. microsoft/vscode#66235 |
Since I was poking around with it, I went ahead and implemented it. The new version seems to mostly be doing the right thing. I'll need to test it some more to see if there's anything it's messing up. |
@nobody-famous the async nature of formatOnType really is horrible to work with, and while formatOnType used to be fairly innocuous, it has recently started being incredibly opinionated with a lot of languages. I hadn't come across OnEnterRules I don't think. What is really silly is with a well specified tmSyntax, vscode will maintain a nested representation, however I haven't found a way to access that information from an extension. Even with formatOnType, I was not able to prevent a slight delay after pressing return before the indentation kicks in, so I had to provide a 'good enough' solution rather than something that felt decent, since Lisp just requires auto indentation to prevent insanity. @PEZ is there a better way to approach this these days? |
The formatOnType doesn't get called until after the static analysis stuff like the OnEnterRules have done their thing. I've got edge cases in my solution I need to deal with at some point because it ends up double indenting things. The format on type code needs to figure out what the vscode static stuff did and adjust that. Since it's doing throw away work, there's a bit of a pause. The problem with Common Lisp is that it's not possible to statically analyze it. Not accurately, anyway. The slime source code is a good example. They have a lot of functions that are defined by macros instead of defun, so the only way to know they're functions is to run the macros. I originally wrote this extension just to be a formatter, but I ended up needing to talk to a running image to do the formatting. It snowballed from there. For other languages, it's fine to leave it to statistic analysis, but lisp has to query the image. Letting the OnEnterRules call the server would be the best solution because it allows for dynamic analysis without doing extra work. It sounds like that won't happen anytime soon because they're concerned about potential performance issues. |
@mseddon, things haven't really improved around this. Calva is relying on the infrastructure you added for this. It works great, btw. 😄 |
@nobody-famous this is why I had to resort to some fairly fun contortions for Calva. Effectively I had a mirrored, lexically analysed copy of the document, and implemented emacs-like paredit navigation like forward-sexpr etc. From there I had heuristics to format the code by examining the surrounding context- crude, but enough to be useful. It was not a particularly fun task however, and has obvious limitations wrt macro expansion as you allude to. It's surprisingly hard to coax vscode into formatting Lisp it seems. |
Still seems really broken for me. here is what I get:
Every time I type anything, auto-indent starts the next line past the end of the previous line, which is about the worst thing it could do. I've tried different language specific settings here, but these have no effect at all:
"none", "full", "advanced"--> all do the same thing. I also tried the editor.autoIndent setting and it also does nothing:
So, something seems to be overriding what happens based on settings. I have searched for indentation and indent in settings.json and nothing pops out at me. I'd be happy to go with VS Code defaults if there is such a thing... or if there is an alive. specific setting? |
I'll look into, that means I broke something. It shouldn't be doing that. The formatter seems to be getting confused. |
Format document works perfectly—very very handy!
This occurs while typing.
From: nobody-famous ***@***.***>
Reply-To: nobody-famous/alive ***@***.***>
Date: Monday, July 31, 2023 at 11:07 AM
To: nobody-famous/alive ***@***.***>
Cc: Lewis Levin ***@***.***>, Comment ***@***.***>
Subject: Re: [nobody-famous/alive] Feature request: new line indenting (#52)
I'll look into, that means I broke something. It shouldn't be doing that. The formatter seems to be getting confused.
Does format document do the right thing? It only does this while typing?
—
Reply to this email directly, view it on GitHub<#52 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAIYWLMGRRRVF2UCPKHOFRLXS7CRDANCNFSM45AYJJTQ>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Are you using other lisp extensions? I'm not able to recreate it so far, so I'm wondering if another extension might also be handling the format on type command and it's double indenting or something. If that's the case, I could add an option to Alive to ignore format on type and let the other extension handle it. |
I am, but only in the attempt to get good formatting. I am very willing to not use the others:
Common Lisp: no mention of formatting or indentation
Paredit: happy to uninstall this as I don’t understand what it actually does. I never installed paredit.js so I don’t know if it installs its own dependencies.
VSCode Scheme: another one I could get rid of as it mostly just does syntax highlighting
Scheme-fmt: can’t even tell if this one is working.
I also do some coding in Gambit Scheme.
I disabled Common Lisp and Paredit and formatting while typing common lisp statements was much improved.
Your suspicion seems confirmed. Let me do some more work and I’ll only report back if the problem seems to re-occur (as I just did only a trivial amount of editing to test your hunch).
From: nobody-famous ***@***.***>
Reply-To: nobody-famous/alive ***@***.***>
Date: Tuesday, August 1, 2023 at 6:18 PM
To: nobody-famous/alive ***@***.***>
Cc: Lewis Levin ***@***.***>, Comment ***@***.***>
Subject: Re: [nobody-famous/alive] Feature request: new line indenting (#52)
Are you using other lisp extensions? I'm not able to recreate it so far, so I'm wondering if another extension might also be handling the format on type command and it's double indenting or something. If that's the case, I could add an option to Alive to ignore format on type and let the other extension handle it.
—
Reply to this email directly, view it on GitHub<#52 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAIYWLIBE4XO2EAVCTUJBHTXTF6BPANCNFSM45AYJJTQ>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Well, further update.
Even with the other extensions disabled, when I enter a new line of text in a common lisp file it gets 3 tabs of 4 stops.
There seems to be a problem with VS Code that it ignores language specific editor. settings. Always the global tabsize setting overrides the language specific. This could also be part of the problem.
From: Lewis Levin ***@***.***>
Date: Wednesday, August 2, 2023 at 7:45 AM
To: nobody-famous/alive ***@***.***>
Subject: Re: [nobody-famous/alive] Feature request: new line indenting (#52)
I am, but only in the attempt to get good formatting. I am very willing to not use the others:
Common Lisp: no mention of formatting or indentation
Paredit: happy to uninstall this as I don’t understand what it actually does. I never installed paredit.js so I don’t know if it installs its own dependencies.
VSCode Scheme: another one I could get rid of as it mostly just does syntax highlighting
Scheme-fmt: can’t even tell if this one is working.
I also do some coding in Gambit Scheme.
I disabled Common Lisp and Paredit and formatting while typing common lisp statements was much improved.
Your suspicion seems confirmed. Let me do some more work and I’ll only report back if the problem seems to re-occur (as I just did only a trivial amount of editing to test your hunch).
From: nobody-famous ***@***.***>
Reply-To: nobody-famous/alive ***@***.***>
Date: Tuesday, August 1, 2023 at 6:18 PM
To: nobody-famous/alive ***@***.***>
Cc: Lewis Levin ***@***.***>, Comment ***@***.***>
Subject: Re: [nobody-famous/alive] Feature request: new line indenting (#52)
Are you using other lisp extensions? I'm not able to recreate it so far, so I'm wondering if another extension might also be handling the format on type command and it's double indenting or something. If that's the case, I could add an option to Alive to ignore format on type and let the other extension handle it.
—
Reply to this email directly, view it on GitHub<#52 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAIYWLIBE4XO2EAVCTUJBHTXTF6BPANCNFSM45AYJJTQ>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Figured it out.
VS Code has this “clever” feature that it remembers a bunch of editor and workbench settings on a per file basis. So, it remembers the settings from the time the file was created. Since I may have had things setup inappropriately and with multiple common lisp extensions active, those files are permanently weird. I suppose there must be some way to clean that up, but it’s not worth the trouble.
With a brand new .lisp file everything seems to work fine.
I guess you should close this because you can’t fix VS Code itself—that’s like going up against city hall and we all know “you can’t fight city hall.”
From: Lewis Levin ***@***.***>
Date: Wednesday, August 2, 2023 at 9:24 AM
To: nobody-famous/alive ***@***.***>
Subject: Re: [nobody-famous/alive] Feature request: new line indenting (#52)
Well, further update.
Even with the other extensions disabled, when I enter a new line of text in a common lisp file it gets 3 tabs of 4 stops.
There seems to be a problem with VS Code that it ignores language specific editor. settings. Always the global tabsize setting overrides the language specific. This could also be part of the problem.
From: Lewis Levin ***@***.***>
Date: Wednesday, August 2, 2023 at 7:45 AM
To: nobody-famous/alive ***@***.***>
Subject: Re: [nobody-famous/alive] Feature request: new line indenting (#52)
I am, but only in the attempt to get good formatting. I am very willing to not use the others:
Common Lisp: no mention of formatting or indentation
Paredit: happy to uninstall this as I don’t understand what it actually does. I never installed paredit.js so I don’t know if it installs its own dependencies.
VSCode Scheme: another one I could get rid of as it mostly just does syntax highlighting
Scheme-fmt: can’t even tell if this one is working.
I also do some coding in Gambit Scheme.
I disabled Common Lisp and Paredit and formatting while typing common lisp statements was much improved.
Your suspicion seems confirmed. Let me do some more work and I’ll only report back if the problem seems to re-occur (as I just did only a trivial amount of editing to test your hunch).
From: nobody-famous ***@***.***>
Reply-To: nobody-famous/alive ***@***.***>
Date: Tuesday, August 1, 2023 at 6:18 PM
To: nobody-famous/alive ***@***.***>
Cc: Lewis Levin ***@***.***>, Comment ***@***.***>
Subject: Re: [nobody-famous/alive] Feature request: new line indenting (#52)
Are you using other lisp extensions? I'm not able to recreate it so far, so I'm wondering if another extension might also be handling the format on type command and it's double indenting or something. If that's the case, I could add an option to Alive to ignore format on type and let the other extension handle it.
—
Reply to this email directly, view it on GitHub<#52 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAIYWLIBE4XO2EAVCTUJBHTXTF6BPANCNFSM45AYJJTQ>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Ok. I've seen similar things from VSCode where I had to nuke a directory and clone from github again to get it to behave. |
The “project directory” .vscode can contain settings we didn’t realize were there…
From: nobody-famous ***@***.***>
Reply-To: nobody-famous/alive ***@***.***>
Date: Saturday, August 5, 2023 at 4:04 PM
To: nobody-famous/alive ***@***.***>
Cc: Lewis Levin ***@***.***>, Comment ***@***.***>
Subject: Re: [nobody-famous/alive] Feature request: new line indenting (#52)
Ok. I've seen similar things from VSCode where I had to nuke a directory and clone from github again to get it to behave.
—
Reply to this email directly, view it on GitHub<#52 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAIYWLPRZITA6LPZBXJXSCTXT2RMNANCNFSM45AYJJTQ>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Currently, when you enter new line, it indents it on same level as previous line.
So, if you enter new line
(declare (optimize (safety 3) (debug 3)))
between (safety 3) and (debug 3), it will indent it as
If it is possible, it would be nice if it would automatically indent it correctly, like
Or if we had such an option
The text was updated successfully, but these errors were encountered: