Skip to content

Fix line comment action for makefiles (Fixes #234464)#243283

Merged
aiday-mar merged 8 commits intomicrosoft:mainfrom
Enzo-Nunes:fix-234464
Jun 6, 2025
Merged

Fix line comment action for makefiles (Fixes #234464)#243283
aiday-mar merged 8 commits intomicrosoft:mainfrom
Enzo-Nunes:fix-234464

Conversation

@Enzo-Nunes
Copy link
Copy Markdown
Contributor

This pull request addresses an old bug (issue #234464) where the line comment action in VS Code failed to correctly handle makefiles. By default, VS Code uses Ctrl + / to comment lines, but for makefiles, comment tokens must be placed in the first column to avoid being just forwarded to the shell.

The issue happened because the line comment action didn't account for the language being edited. This fix passes the languageId to the comment function, allowing it to handle makefiles differently. A new test has been added to verify this functionality.

To test this in practice, open any makefile and try using the keybind Ctrl + / on an indented line of code, with and without my fix. You will notice the different placement of the comment token.

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Comment thread src/vs/editor/contrib/comment/browser/lineCommentCommand.ts Outdated
@aeschli aeschli assigned hediet and unassigned aeschli Mar 14, 2025
@Enzo-Nunes Enzo-Nunes requested a review from aeschli March 15, 2025 02:08
@Namiland
Copy link
Copy Markdown

Hi

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

@hediet Hello! I see you are now assigned to this PR. A colleague of yours requested some changes and I've worked on a fix which I just published. You might want to take a look at that. :)

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

@hediet @aeschli Has any of you had any time to take a look? If you need me to review anything, refactor code or either rebase or merge my branch, let me know.

@hediet hediet assigned aiday-mar and unassigned hediet Mar 24, 2025
@hediet
Copy link
Copy Markdown
Member

hediet commented Mar 24, 2025

Thanks for the PR!
Two things: Columns are generally 1 based in VS Code.
Also, I doubt a different value than 1 would ever make sense for lineCommentTokenColumn, so I think that property should be refactored into a boolean.

Are you sure there is no way to do that with existing functionality? E.g. a regexp that matches the \n character? @aiday-mar might know more here

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

@hediet Thank you for the response. I agree! A boolean value would much probably be enough, I'll refactor that and add a commit.

Also, I've taken a good look at the source code which handles this kind of line comment action, and I don't see a more optimal way of accomplishing this with already existing functionality. You mentioned using a regexp that matches '\n', but I don't see how that would be useful to address the issue. Could you clarify a little further?

@aiday-mar any help is welcome, of course. :)

@hediet
Copy link
Copy Markdown
Member

hediet commented Mar 24, 2025

Could you clarify a little further?

I'm not very familiar with this code, but I remember other situations where that helped. Could be very well that it doesn't apply here!

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

I understand. Out of my head I don't think that would help address this case, but I'll take another look regardless. I'll post a commit once the code is refactored.

@aiday-mar
Copy link
Copy Markdown
Contributor

Hi @Enzo-Nunes thanks for the PR. I see you added a new field to the language configuration file called the lineCommentTokenColumn to define a custom value for the index at which to insert the comment. I wonder if we should be introducing such a field as this is makefile specific? I wonder if there are other languages that require comment insertion at a specific index? Letting @aeschli comment here

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

@aiday-mar Hello! Although this is makefile specific, @aeschli instructed me to not to hard code "makefile" into the line comment action code. As such, I've changed the fix to solve the issue through the language configuration service with that new lineCommentTokenColumn field.

While this means that this new field becomes available to every language, its usage is completely optional. The only place where this value is indeed set is in the language-configration.json of makefiles. This solution addresses the issue for makefiles and can also be used by other languages by changing their own configuration files to include this new field.

As @hediet suggested, I'll be refactoring the fix to only include a boolean value which indicates if the comment token should be placed adjacent to the leftmost column or not, resulting in an even simpler solution. I'll publish a commit later today.

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

@hediet I've refactored the fix into a boolean value, as requested. Also, you mentioned columns are 1 based, but since we're no longer using a number I assume that's not a problem anymore.

Let me know if you want any more changes to be made or if it's time to rebase.

@RedCMD
Copy link
Copy Markdown
Contributor

RedCMD commented Mar 24, 2025

I doubt a different value than 1 would ever make sense for lineCommentTokenColumn, so I think that property should be refactored into a boolean.

@hediet @aiday-mar

the language here requires the comment token to be in the 2nd column
microsoft/vscode-discussions#2363
it may work if the comment token is set to " #"

@Enzo-Nunes can you test if setting the comment token to ' #' results in ctrl+/ continuing to work correctly?
(with # in the 2nd column)

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

@Enzo-Nunes can you test if setting the comment token to ' #' results in ctrl+/ continuing to work correctly? (with # in the 2nd column)

It does! If you set the field lineCommentTokenFirstColumn to 'true' and set the comment token to something like ' #', it toggles comments correctly while placing the comment token on the 2nd column.

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

@aeschli @hediet have you guys had the time to take a look? Do you agree with the solution?

@aiday-mar
Copy link
Copy Markdown
Contributor

Hi @Enzo-Nunes Thank you for the ping. I will discuss this idea with my team. I am not sure if we should be modifying the language configuration file schema to support this case. I will let you know what we discuss.

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

Alright! I'll be waiting. Thank you for your support.

@aiday-mar
Copy link
Copy Markdown
Contributor

Hi @Enzo-Nunes thanks for the PR. I have not yet received word from my colleagues. I will bring it up this week or next in a meeting.

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

Thank you very much for the attention! I'll be waiting for new developments.

@aiday-mar aiday-mar requested review from aiday-mar and removed request for aeschli May 13, 2025 07:34
@aiday-mar
Copy link
Copy Markdown
Contributor

aiday-mar commented Jun 2, 2025

Hi @Enzo-Nunes yes apologies. I discussed this PR with my colleagues and they suggested the following. Perhaps we should change the field:

lineComment?: string | null;
to :

lineComment?: string | { comment: string; noIndent?: boolean } | null

This way we do not add a new field but extend the existing field so it can also be of type object that takes as an option the noIndent boolean. This boolean should by default be false. To make this cleaner, I would extract the object type into a separate interface.

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

Alright! I'll make those changes and get back to you.

Pass languageId to _analyzeLines to distinguish makefiles
from the rest of the languages.

Add test to _analyzeLines specifically for makefiles.
…dd comment rule to specify fixed column token placement. Change test scope to test line command instead of just testing the _analyzeLines method.
@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

@aiday-mar I've applied the changes you requested and the code looks even cleaner now!

I've also had to update the branch so everything compiled correctly on my end, so I had to force-push the rebase.

If there is anything else you want changed or clarified, let me know.

Thank you!

@aiday-mar
Copy link
Copy Markdown
Contributor

Hi @Enzo-Nunes thanks for the consistent work! I will have a look.

@aiday-mar
Copy link
Copy Markdown
Contributor

Hi @Enzo-Nunes I have had a look and will push some minor polish changes which do not change the logic. I will put an approval but I think we should merge this next week. This week we are preparing our next release and only critical changes are going into the code base.

@Enzo-Nunes
Copy link
Copy Markdown
Contributor Author

@aiday-mar Alright, I understand. Thank you very much for the time and assistance. :)

@aiday-mar aiday-mar added this to the June 2025 milestone Jun 5, 2025
@sandy081
Copy link
Copy Markdown
Member

sandy081 commented Jun 5, 2025

@aiday-mar I see this is a contribution from the community and since we are in endgame week, is this required to be fixed, given that the bug it is fixing is in backlog and old

Edit: Ok, I see it is planned for June and Auto merge is disabled. I came across this in the code-review channel and therefore raised the flag.

@aiday-mar
Copy link
Copy Markdown
Contributor

Hi @sandy081 yep, I plan to merge this next week during debt week

@aiday-mar aiday-mar enabled auto-merge (squash) June 6, 2025 09:18
@aiday-mar aiday-mar dismissed aeschli’s stale review June 6, 2025 09:22

Dismissing after reviewing again

@aiday-mar aiday-mar merged commit d9145a2 into microsoft:main Jun 6, 2025
7 checks passed
@Enzo-Nunes Enzo-Nunes deleted the fix-234464 branch June 6, 2025 09:49
@Enzo-Nunes Enzo-Nunes restored the fix-234464 branch June 6, 2025 09:53
@yCodeTech
Copy link
Copy Markdown

And with 1 simple language configuration change, it breaks probably lots of comment extensions that rely on the lineComment being a string. (I was using the String.prototype.includes() to check for a specific comment type which now throws an error when encountering makefile language). Luckily I have a fix for it, but 100s of extensions potentially have been affected.

@RedCMD
Copy link
Copy Markdown
Contributor

RedCMD commented Jul 11, 2025

VSCode really should provide a getLanguageConfiguration()
we already have setLanguageConfiguration()

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Jul 21, 2025
@Enzo-Nunes Enzo-Nunes deleted the fix-234464 branch March 12, 2026 16:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants