Skip to content

Conversation

mcanouil
Copy link
Contributor

@mcanouil mcanouil commented Feb 8, 2025

Implement a mechanism to prevent code cell options from being formatted, ensuring that only relevant code is affected during formatting operations.

@mcanouil mcanouil marked this pull request as ready for review February 9, 2025 15:13
@cscheid
Copy link
Contributor

cscheid commented Feb 21, 2025

Thanks for the PR.

I assume this was done to prevent black and other Python auto-formatting tools from mangling our #| syntax. Is that the case? If so, I wonder if a more targeted, Python-only fix is better.

@cscheid
Copy link
Contributor

cscheid commented Feb 21, 2025

Another thought here is that this kind of PR really makes me wish we had a test suite in this repo.

@mcanouil
Copy link
Contributor Author

mcanouil commented Feb 21, 2025

I assume this was done to prevent black and other Python auto-formatting tools from mangling our #| syntax. Is that the case? If so, I wonder if a more targeted, Python-only fix is better.

I was thinking about making it specific at first but then I realised that the expected comments are all hardcoded, so I reconsidered, and made a general protection for the comments symbols (hardcoded in two places).

Another thought here is that this kind of PR really makes me wish we had a test suite in this repo.

I'm not yet very familiar on this part, but I can't agree more with this.
That's on my personal roadmap before releasing Quarto Wizard 1.0.0.

I did "manual tests" as far as this approach can go.

@mcanouil
Copy link
Contributor Author

Let's hold on on this PR as the behaviour is not new at all so it can wait a bit for me to implement a test soon as I get some spare time.

@mcanouil mcanouil marked this pull request as draft March 3, 2025 20:10
@vezwork
Copy link
Collaborator

vezwork commented Sep 9, 2025

@mcanouil we now have extension tests! If you're interested in merging this PR, want to add some tests?

@juliasilge
Copy link
Collaborator

We are continuing to get more user reports of this such as in posit-dev/positron#9432, so I'd love to see a test written here so we can merge this fix in!

@mcanouil
Copy link
Contributor Author

mcanouil commented Sep 18, 2025

I'll try to make some time to make this happen.

@mcanouil
Copy link
Contributor Author

mcanouil commented Oct 5, 2025

I've setup the test, but I can't get to make the formatting command to work.
I'm missing something, maybe related to vdoc or something else ...

npx @vscode/test-cli --grep "Code Block Formatting" --install-extensions "ms-python.black-formatter"

I don't know how to trigger all the logic of the formatCellCommand

The easiest would be to export formatActiveCell(), but we don't want to export that only for a test.

I've also tried to trigger the whole document formatting, but it does not work for an unknown reason.

I have to drop this for now, but if someone has a better understand of the whole formatting logic of the extension (not that trivial) and knows how to trigger the activation, feel free to take over.

@juliasilge
Copy link
Collaborator

juliasilge commented Oct 5, 2025

Ah, I don't think we can use any other extensions in the tests, because of the way that they use a special build of VS Code that is specially built for running extension tests.

Instead, what we'll want to do is mock out a formatter to run in the tests. This is the same thing that #754 needs. We may want to put the formatting mock somewhere that all tests can use it.

I also think that exporting a function to use in a test is a very good/reasonable way to go.

@mcanouil
Copy link
Contributor Author

mcanouil commented Oct 5, 2025

Well, @vscode/test-cli does support installing extensions and it is used here, even when calling via yarn.

I don't think the issue is the presence/absence of the formatter.

I can only make the test install the extension to be sure yarn run test has it when running.

@mcanouil
Copy link
Contributor Author

mcanouil commented Oct 5, 2025

Ok, now I have some information. The vscode-test instance shows a notification that the selection marker is not within a cell that supports formatting which is clearly wrong, but no clue why quarto displays this.

"Editor selection is not within a code cell that supports formatting."

from FormatCellCommand.
So now the command is triggered.

yarn run test --grep "Code Block Formatting" 

@vezwork
Copy link
Collaborator

vezwork commented Oct 15, 2025

For reference: In another PR I added a mocked cell formatter in a test here: 873fcab

@mcanouil
Copy link
Contributor Author

@vezwork Thanks, I'll try to take a look next week-end and see to finalise this PR.

@mcanouil
Copy link
Contributor Author

mcanouil commented Oct 19, 2025

Even changing to your testFormatter function does not work.
Note that the formatting do work as it should but I really don't understand what is going on with this VSCode extension during testing.

See when running extension debug mode:

Screen.Recording.2025-10-19.at.19.10.58.mov

I have to drop this as It costs me way too much time for no good reasons.

Feel free to take over as I won't spend more time on this for the next few months at least.

Added subtitle with link to pull request for context.
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.

4 participants