Skip to content
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

Auto-completion for packages #44

Open
mahrud opened this issue Apr 27, 2023 · 11 comments
Open

Auto-completion for packages #44

mahrud opened this issue Apr 27, 2023 · 11 comments
Labels
enhancement New feature or request

Comments

@mahrud
Copy link
Member

mahrud commented Apr 27, 2023

When running M2 from the terminal, if you load a package, all exported package symbols can be tab-auto-completed. In Emacs, however, this doesn't happen.

The reason is clear: Emacs auto-completion is tied to the syntax highlighter which is fixed to the pre-loaded packages. I suspect auto-completion can be made to work. Is it possible for emacs to communicate with readline?

A possible solution might be to also generate per-package syntax-highlighting and auto-completion lists, and somehow making Emacs know to load those additional lists whenever a package is loaded. Is this possible?

@DanGrayson
Copy link
Member

We could simply add symbols for all packages to the default list.

@mahrud
Copy link
Member Author

mahrud commented Apr 27, 2023

It would be misleading if a word gets highlighted or autocompleted by M2, but it's just a symbol in M2 because the corresponding package hasn't been loaded yet, or maybe the package is something irrelevant to the user.

Moreover, your suggestion is still incongruent with the behavior of M2 in a terminal.

@d-torrance
Copy link
Member

I haven't tested it yet, but this Emacs package might be helpful for this: https://github.com/monsanto/readline-complete.el

@mahrud mahrud changed the title Completion for packages Auto-completion for packages Apr 30, 2023
@mahrud mahrud added the enhancement New feature or request label Apr 30, 2023
@d-torrance
Copy link
Member

I've been thinking about a possible solution for this problem, so that TAB in Emacs would give all the same symbols as in the terminal using readline.

  • We could add the ability to call completions from expr.d at top-level (this is what readline uses), possibly as complete(String) since complete already exists as a method.
  • The Emacs completion function could then call this and instead of printing the output as usual, parse it and use it to form the list of possible completions.

The Python major mode does something similar.

The big difference in Macaulay2, though, is that we have output line numbers and variables like oo and ooo that we wouldn't want to muddy up. One possible (but pretty hacky) idea is to introduce a new type of list that this function could return with its own AfterEval method that doesn't update the output variables or line number.

@mahrud
Copy link
Member Author

mahrud commented Feb 28, 2024

This sounds promising, but before putting in much work I'd rather make sure this is the right direction for getting auto completion working on vscode and other modern editors as well.

@etdavila10 pointed me to LSP in this direction.

@d-torrance
Copy link
Member

I have a very early draft of an M2 LSP server, so I'm definitely interested in moving in that direction at some point!

@mahrud
Copy link
Member Author

mahrud commented Feb 28, 2024

Btw, apropos "^bla" might already do what you wanted, no?

Do you know if using LSP would require an instance of M2 (or perhaps a dedicated thread communicating via a side channel)?

@d-torrance
Copy link
Member

Btw, apropos "^bla" might already do what you wanted, no?

Yes, I think it might!

Do you know if using LSP would require an instance of M2 (or perhaps a dedicated thread communicating via a side channel)?

That's currently how my draft is implemented, yes. Emacs or VS Code or whatever would be communicating with a second M2 instance running the server.

@mahrud
Copy link
Member Author

mahrud commented Feb 29, 2024

Yes, I think it might!

To be clear, I think perhaps apropos should call completions from expr.d instead, assuming you can also search based on a piece in the middle of an expression.

@etdavila10
Copy link

I have a very early draft of an M2 LSP server, so I'm definitely interested in moving in that direction at some point!

This is very exciting! I would be more than happy to contribute to an M2 LSP as I think it would be extremely beneficial to future M2 development.

@d-torrance
Copy link
Member

@etdavila10 -- Awesome!

This is the branch that I've been working on: https://github.com/d-torrance/M2/tree/lsp

Everything is in M2/Macaulay2/packages/LanguageServer.m2 or the corresponding subdirectory.

So far, it can successfully send and receive JSON-RPC messages with the editor, but the initialization step is failing for some reason I never quite figured out. I haven't touched it since last summer, so my memory is a little hazy. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants