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

Problems with utf-8 code #2

Open
simonjwright opened this issue Nov 19, 2024 · 5 comments
Open

Problems with utf-8 code #2

simonjwright opened this issue Nov 19, 2024 · 5 comments

Comments

@simonjwright
Copy link

I raised this issue over on ada_language_server.

The last comment is interesting. Joao suggests we could set ada.defaultCharset the same was we set ada.projectFile, but as far as I can see we just ask the server what it thinks the default project file is! I had a look through the code but my elisp is a bit weak, and I’m a bit vague on the LS protocol.

Would ada.defaultCharset be the same for the whole project? that might not be right. Emacs on macOS knows whether a buffer is UTF or not.

I’m getting on very well with ada-ts-mode (so long as I avoid utf-encoded source! I get the feeling that as soon as ALS sees a utf-encoded file in a project it gets very confused).

@brownts
Copy link
Owner

brownts commented Nov 19, 2024

I raised this issue over on ada_language_server.

The last comment is interesting. Joao suggests we could set ada.defaultCharset the same was we set ada.projectFile, but as far as I can see we just ask the server what it thinks the default project file is! I had a look through the code but my elisp is a bit weak, and I’m a bit vague on the LS protocol.

ada-ts-mode itself doesn't configure the Ada Language Server. The configuration is handled through the LSP client that you use (i.e., Eglot or lsp-mode). That's why ada-ts-mode queries either the LSP client configuration or LSP server, for the project file, when it needs it. If you don't explicitly configure the project file through the LSP client, the Ada Language Server can often find it itself.

Assuming you use Eglot as your LSP client, you can configure the equivalent of the VSCode .vscode/settings.json mentioned in the other issue with a .dir-locals.el file as follows:

((nil . ((eglot-workspace-configuration . (:ada ( :projectFile "utf.gpr"
                                                  :defaultCharset "utf8"))))))

If you use lsp-mode instead, let me know and I can provide the equivalent configuration for that as well.

The Eglot command M-x eglot-show-workspace-configuration provides a JSON version of the configuration so you can check whether you configured it as you expected, since it's easy to mess up the property list format that Eglot uses. For some additional detail on the Eglot configuration format, see here.

Would ada.defaultCharset be the same for the whole project? that might not be right. Emacs on macOS knows whether a buffer is UTF or not.

Yes, this is an ALS workspace configuration. You can see the specific ALS documentation for the setting here. I'm unclear on exactly what situation it applies, but the docs indicate it's used when the ALS has to read the file itself. AdaCore can probably provide specifics if needed.

I’m getting on very well with ada-ts-mode (so long as I avoid utf-encoded source! I get the feeling that as soon as ALS sees a utf-encoded file in a project it gets very confused).

I'm glad ada-ts-mode is working well for you. I still have plenty of work to do on it, but I'm glad that in its current state it is still useful. Hopefully the above settings will solve your issue.

@simonjwright
Copy link
Author

If you use lsp-mode instead, let me know and I can provide the equivalent configuration for that as well.

That would be a great help, thanks

@brownts
Copy link
Owner

brownts commented Nov 20, 2024

FYI, I just noticed that the VSCode settings.json that @joaopsazevedo provided in the other issue uses "utf8" for the value of defaultCharset. The documentation shows a dash in the value (i.e., "UTF-8"). I'm not sure if that is significant, but it might be good to try it both ways.

The Ada language configuration options for lsp-mode are documented here. There are only a handful of options listed there, but I have a PR pending (see emacs-lsp/lsp-mode#4567) that I need to follow up on to add the missing ones. However, the ones you're interested in right now are already available.

By default, lsp-mode configures the "charset" option to UTF-8, but the equivalent (to the above) .dir-locals.el configuration for lsp-mode would look like this (again, I'm unclear about the lack of a "-" in "utf8"):

((nil . ((lsp-ada-project-file . "utf.gpr")
         (lsp-ada-option-charset . "utf8"))))

@simonjwright
Copy link
Author

It doesn’t seem to make any difference to the issues, so I think either must be acceptable.

I see that both of those variables are customizable! The .dir-locals.el setting means that ALS gets both the lsp-ada-option-charset-originated "UTF-8" and then "utf8".

@brownts
Copy link
Owner

brownts commented Nov 20, 2024

It doesn’t seem to make any difference to the issues, so I think either must be acceptable.

Unfortunately, I'm not able to reproduce it on my Linux system. I've tried both Eglot and lsp-mode as well as ALS versions 25.0.20240915 and 26.0.20241117 and can't seem to trigger this issue.

Does the error still happen on VSCode with the suggested settings from @joaopsazevedo? If not, since VSCode defaults to using GNATformat, you could try enabling that as well and see if it still happens.

((nil . ((eglot-workspace-configuration . (:ada ( :projectFile "utf.gpr"
                                                  :defaultCharset "utf8"
                                                  :useGnatformat t))))))

If that still doesn't work, I'd recommend generating an ALS log and attaching it to the original issue.

I see that both of those variables are customizable! The .dir-locals.el setting means that ALS gets both the lsp-ada-option-charset-originated "UTF-8" and then "utf8".

The "double initialization" will happen if you enable lsp in ada-ts-mode-hook instead of the buffer-local hack-local-variables-hook since lsp-mode is enabled prior to the .dir-locals.el being read, after which the change to the variable causes a workspace update to be sent to the server. I probably should update the example in https://github.com/brownts/dotemacs-ada to enable it after the variables are initialized. The following should do the equivalent of what I'm describing:

(defun init.el/lsp-mode ()
  (add-hook 'hack-local-variables-hook #'lsp t 'local))

(add-hook 'ada-ts-mode-hook #'init.el/lsp-mode)

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

No branches or pull requests

2 participants