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

Spurious asterisk is inserted on new line if the previous one starts from the space(s) followed by asterisk #5733

Closed
UR3IQO opened this issue Jul 7, 2020 · 9 comments
Assignees
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. help wanted Can be fixed in the public (open source) repo. Language Service quick fix verified Bug has been reproduced
Milestone

Comments

@UR3IQO
Copy link

UR3IQO commented Jul 7, 2020

Type: LanguageService

Describe the bug

  • OS and Version: Windows 8.0
  • VS Code Version: 1.46.1
  • C/C++ Extension Version: 0.28.3
    When editing C code expression spurious asterisk is inserted on the new line if the previous line starts from the space(s) followed by asterisk

Steps to reproduce
Create new .c file. Enter the following code:

void a(void)
{
   int x = 1 
         * 1 + 1
}

Put cursor before the + and hit enter. If there is one or more space(s) before the aterisk, spurious asterisk will be inserted on the new line. See the record:
vscode7

The very bad thing is that the code with the asterisk added may compile without any warnings or errors, but you will get wrong result (for example multiplication instead of addition or subtraction).

The problem roots are probably from the automatic asterisk insertion function when editing comments in the following form:

/*************
 *
 *
 **************/

If so, that function should be activated only if the comment is edited.

@sean-mcmanus sean-mcmanus self-assigned this Jul 7, 2020
@sean-mcmanus sean-mcmanus added bug Language Service verified Bug has been reproduced help wanted Can be fixed in the public (open source) repo. labels Jul 7, 2020
@sean-mcmanus sean-mcmanus removed their assignment Jul 8, 2020
@sean-mcmanus
Copy link
Collaborator

The code that implements this is at https://github.com/microsoft/vscode-cpptools/blob/release/Extension/src/LanguageServer/languageConfig.ts#L229 if anyone wants to debug/fix it.

I debugged it, but I didn't see what was wrong with the generated regex's (and I don't have currently have time to continue investigating).

@bobbrow
Copy link
Member

bobbrow commented Jul 8, 2020

When I implemented this, I emulated what VS Code was doing for TypeScript. I seem to recall this being a problem for TypeScript too, but since I tried it again, it looks like they have a way to disable it for the case you've shared.

I believe this is the set of rules for TypeScript: https://github.com/microsoft/vscode/blob/e5ceb315da2462b0fea70716e79cc82ce708b438/extensions/typescript-language-features/src/features/languageConfiguration.ts#L21

EDIT: I think this is the commit that changed the behavior: microsoft/vscode@81f5833#diff-5fa357ec086244b9f81089781bd6e25b. There appears to be a new property that can be used to ensure the * is not added.

@bobbrow bobbrow added this to the On Deck milestone Jul 9, 2020
@bobbrow
Copy link
Member

bobbrow commented Jul 9, 2020

Also mentioned in #2072

@UR3IQO
Copy link
Author

UR3IQO commented Jul 10, 2020

I can confirm that adding to settings "C_Cpp.commentContinuationPatterns": [] (as recomeded in the #2072) solves the problem. Of cause it also disables this function in the comments, but that is not a big problem.

@bobbrow bobbrow modified the milestones: On Deck, 1.1.0 Aug 28, 2020
@bobbrow bobbrow modified the milestones: 1.1.0, 1.2.0 Oct 20, 2020
@bobbrow bobbrow modified the milestones: 1.2.0, 1.3.0 Jan 7, 2021
@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Mar 23, 2021
@clement-analogue
Copy link

This bug is has a bug. At new line in a comment section, the asterisk is not automatically inserted anymore.

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Mar 26, 2021

@UR3IQO Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/1.3.0-insiders2 , except for the issue mentioned by @clement-analogue

@elahehrashedi I can repro the issue with

/**
 * 

2nd newline doesn't continue the "*".

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Mar 26, 2021

@clement-analogue @elahehrashedi The change at #7238 fixes the issue (unless we find some problem with it later).

UPDATE: My fix wasn't sufficient in the repro:

int n = 3
    * 4
    * 5  // Enter here

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Mar 31, 2021

Although the original repro with one "*" is fixed, this case

int n = 3
    * 4
    * 5  // Enter here

with 2 consecutive "*" is going to cause "*" to be added to the new line (with 1.3.0-insiders3) -- the same bug occurs with TypeScript and even with the GitHub editor. If that is a problem you should a file a new bug against VS Code, but I'm guessing they won't fix it.

@michelleangela
Copy link
Contributor

Fix is released in the 1.3.0 release version https://github.com/microsoft/vscode-cpptools/releases/tag/1.3.0

@github-actions github-actions bot locked and limited conversation to collaborators May 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. help wanted Can be fixed in the public (open source) repo. Language Service quick fix verified Bug has been reproduced
Projects
None yet
Development

No branches or pull requests

6 participants