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

Add formatter #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add formatter #46

wants to merge 1 commit into from

Conversation

adoebber
Copy link

I added automatic code formatting.

The readme already says "Automatic formatting", but I could not find the code for it. Am I missing something?

@5nord
Copy link
Member

5nord commented Nov 3, 2024

Yeah, experimental features such as formatting are hard to find. To use them you have to enable them manually in the settings.json file. Open the command palette (CTRL+SHIFT+P), search for "settings json" and then add the key you are interested in. In your case "ttcn3.experimental.format.enabled": true

Screenshot From 2024-11-03 09-36-41

Formatting is not enabled by default, because there are still some minor bugs. I plan to update the TTCN-3 parsers to the latest standards, this will be a good opportunity to fix and release the formatting feature.

Your pull request is very appreciated, however I won't merge it since I believe it won't be needed for much longer. Is this satisfactory?

@adoebber
Copy link
Author

adoebber commented Nov 4, 2024

When I add that line to my settings.json, it is inactive (as in your screenshot) and VSCode says that no formatter is installed for ttcn3. I have tested that with the extension 0.8.0 from the marketplace. Furthermore if I search for the keyword "format" in this repository I cannot find the source code that registers a formatter. What am I overlooking?

@5nord
Copy link
Member

5nord commented Nov 5, 2024

I believe it is shown as inactive because experimental settings are not declared in the package.json manifest. But it still works with various vscode versions. I could not test the behaviour with Windows, though.

The code responsible for formatting is implemented in the language server that is used by this extensions: https://github.com/nokia/ntt/blob/v0.18.0/internal/lsp/configuration.go#L34-L54

It look a bit complicated because some editors do not have support for dynamic registration.

Do you have an idea what the problem could be?

@adoebber
Copy link
Author

adoebber commented Nov 5, 2024

I have no idea what the problem is. VSCode just says, that there is no registered formatter when I do F1 -> "format document".

I was not aware of the dynamic registration of language servers. Since I cannot find the root cause of the problem, we would stick with this solution as a workaround. But I can understand, if you do not want to accept this PR.

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

Successfully merging this pull request may close these issues.

2 participants