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

Editor gets angry with C++ in Header files. #2961

Closed
CarlBeniz opened this issue Oct 12, 2023 · 7 comments · Fixed by #2962
Closed

Editor gets angry with C++ in Header files. #2961

CarlBeniz opened this issue Oct 12, 2023 · 7 comments · Fixed by #2962

Comments

@CarlBeniz
Copy link

I have been using version 2.0.10 to write C++ for about a year and noticed that the syntax highlighting for the headerfiles (*.h) was off, but didn't mind too much. Recently, I noticed that this version of the editor seems to default to Objective-C for header files, so I set it to C++, which fixed the highlighting, but instead started complaining about the code when saving the document. Since this code was legal and compiled without any warnings or notes from the compiler (g++ of GCC), I assumed it was a bug and updated the editor to 2.0.12.
Now, the editor not only gets angry when filetype is set to 'c++', but saving with the default/assumed filetype (which is 'c' with this version) also makes it complain. This did not happen previously.

2.0.10: If default is Objective-C, it does not get angry when saving, but if set explicitly it would be. If default is C, it would be.
2.0.12: The default is now C, and it gets angry by default.

When filetype is set to 'c++', which is what I want to do, commenting out and moving code makes it upset with different things, and it will even remember the line it used to get angry with, even if the code is removed and the file is saved.
micro_cpp_h_issue_001

This is only an issue with C++ code in *.h-files, *.cpp-files do not upset the editor.

Commit hash: c2cebaa
OS: Zorin OS 16.1
Terminal: GNOME Terminal 3.36.2

@JoeKar
Copy link
Collaborator

JoeKar commented Oct 12, 2023

Hi, this is related to the respective linter and his setup is used based on the detected file type. Currently the file type detection is somehow inaccurate, which then impacts the used linter.
This maybe gets better in the moment #2819 will be merged.

Since you named your C++ header with *.h extension it will be detected as C header file instead of C++ header file. This can be corrected by renaming the extension or after the above PR, when we additionally add namespace to the signature of the C++ syntax YAML file.

Long story short (updated):
Actually the triggers are properly performed, but since the invoked linter changes the created messages of the previous linter aren't removed.

@flber
Copy link
Contributor

flber commented Oct 25, 2023

I'm excited to see #2819 merged in general (I think the idea of signatures is great, and so much more flexible than the filename detect!), so I'm curious: would the solution using the patched code be to add something like a signature: "namespace" tag to the cpp.yaml syntax file?

@JoeKar
Copy link
Collaborator

JoeKar commented Oct 26, 2023

would the solution using the patched code be to add something like a signature: "namespace" tag to the cpp.yaml syntax file?

That was the intention, but unfortunately the file extension check kicks in again. Anyway I provided the example with 2aa386f within #2819.

@flber
Copy link
Contributor

flber commented Nov 2, 2023

Ahh, I see. What might a temporary fix for that be then, is that something stored on configs or at the source code level? I'd love to get micro linting working with cpp projects, even if it's just a quick hack :)

@JoeKar
Copy link
Collaborator

JoeKar commented Nov 2, 2023

You can force your file to be interpret as C++ file and then you can use the adaptations of #2962 to move the linter into the right direction. ;)

options.md...

filetype: sets the filetype for the current buffer. Set this option to off to completely disable filetype detection.

set filetype c++

;)

@flber
Copy link
Contributor

flber commented Nov 3, 2023

Yesssss, thank you @JoeKar! I ended up merging the fix/linter-ft-relation branch into your main branch because why not, and now it works! That's seriously so nice to have working, thank you for the help

@jxu
Copy link

jxu commented Dec 26, 2024

btw you should be using .hpp for C++ header files

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 a pull request may close this issue.

4 participants