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

Provide API to retrieve or listen for registered document formatter IDs #135674

Closed
adalinesimonian opened this issue Oct 22, 2021 · 4 comments
Closed
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@adalinesimonian
Copy link

Issue Type: Feature Request

It'd be great to have a way in the VS Code API of retrieving which document formatters are currently registered or a notification for when a document formatter is registered.

Over at vscode-stylelint we have e2e tests that start up VS Code and test various extension features, one of which is document formatting. However, there doesn't seem to be a way to know for certain that document formatting has been registered before executing the test. As a result, while changing the extension's activation event from * to onStartupFinished, the document formatter test has become flaky.

In other tests, we are able to retrieve and wait on whatever it is we want tested, such as, for example, a command. However, the only instance I've been able to find of code that is able to the same or similar with document formatters is part of the private API. If something similar, whether notification- or polling-based, existed, it'd perfectly fit this use case.

If I've missed any similar API endpoints that are already in place, please feel free to let me know!

VS Code version: Code 1.61.2 (6cba118, 2021-10-19T14:57:20.575Z)
OS version: Windows_NT x64 10.0.22000
Restricted Mode: No

@jrieken
Copy link
Member

jrieken commented Oct 25, 2021

Over at vscode-stylelint we have e2e tests that start up VS Code and test various extension features, one of which is document formatting.

Is that your extension e2e? Iff so could know by exposing an API from you extension to those tests right?

@jrieken jrieken added the info-needed Issue requires more information from poster label Oct 25, 2021
adalinesimonian added a commit to stylelint/vscode-stylelint that referenced this issue Oct 25, 2021
Added so that formatter test can wait until formatter is registered
since VS Code has no API to check if a formatter with a given ID exists.

See microsoft/vscode#135674
@adalinesimonian
Copy link
Author

We didn't have an API yet, so I:

It definitely works, but it feels clunky having to add a notification to an editor-agnostic language server for testing purposes in a specific editor.

I won't bikeshed, though, if an API endpoint for getting document formatters by ID or something similar to the same effect is not something y'all are interested in adding or accepting as a contribution.

@jrieken
Copy link
Member

jrieken commented Oct 26, 2021

Yeah, it is that we don't have plans to expose such API - we try to keep it minimal and its purpose is to drive the editor itself, not so much be infrastructure.

Given this is all e2e an easier approach might be simply self-activate your extension in tests (see Extension#activate. This requires that your extension registers its formatter during activate but most do

@jrieken jrieken closed this as completed Oct 26, 2021
@adalinesimonian
Copy link
Author

Yeah, it is that we don't have plans to expose such API - we try to keep it minimal and its purpose is to drive the editor itself, not so much be infrastructure.

Totally fair.

Given this is all e2e an easier approach might be simply self-activate your extension in tests (see Extension#activate. This requires that your extension registers its formatter during activate but most do

The extension is being activated in time — we have a global beforeAll that makes sure it is — rather, it's the delay between the extension's activation and the formatter being registered dynamically by the language server that was causing the test failures. But we're good for now with this workaround; hopefully, if anyone comes across this issue with a similar problem this discussion will be helpful for them.

adalinesimonian added a commit to stylelint/vscode-stylelint that referenced this issue Oct 27, 2021
* refactor: Activate on `onStartupFinished`

Closes #214

Stops this extension from slowing VS Code during startup.

* feat: add API, formatter registration notification

Added so that formatter test can wait until formatter is registered
since VS Code has no API to check if a formatter with a given ID exists.

See microsoft/vscode#135674

* docs: add entry to changelog
@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants