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

FR Source Code window: configurable source highlighting #434

Closed
GitMensch opened this issue Nov 29, 2022 · 15 comments · Fixed by #448
Closed

FR Source Code window: configurable source highlighting #434

GitMensch opened this issue Nov 29, 2022 · 15 comments · Fixed by #448

Comments

@GitMensch
Copy link
Contributor

Is your feature request related to a problem? Please describe.
In some "rarer" cases the highlighter chooses the wrong syntax, it seems that this is all filename (extension) based now:

const auto sourceCode = QString::fromUtf8(file.readAll());
m_document->clear();
m_highlighter->setDefinitionForFilename(disassemblyOutput.mainSourceFileName);
m_document->setPlainText(sourceCode);

Describe the solution you'd like
An option to change the language the highlighter uses, ideally also away to see what highlighter is used.
I'd suggest to add a footer line to the source window which has a label "syntax" and a drop down to choose between the available syntax (also showing which syntax is used). For performance reasons the list should only be created when the Disassembly View is opened the first time (or was closed).

Additional context
This is most likely to happen with preparsed files (bison/flex/embedded sql preprocessors/...) - and also with "uncommon" file extensions.

lievenhey added a commit that referenced this issue Dec 5, 2022
lievenhey added a commit that referenced this issue Dec 5, 2022
lievenhey added a commit that referenced this issue Dec 5, 2022
lievenhey added a commit that referenced this issue Dec 5, 2022
lievenhey added a commit that referenced this issue Dec 5, 2022
lievenhey added a commit that referenced this issue Dec 6, 2022
lievenhey added a commit that referenced this issue Dec 7, 2022
lievenhey added a commit that referenced this issue Dec 7, 2022
lievenhey added a commit that referenced this issue Dec 7, 2022
lievenhey added a commit that referenced this issue Dec 9, 2022
lievenhey added a commit that referenced this issue Dec 9, 2022
lievenhey added a commit that referenced this issue Dec 9, 2022
milianw pushed a commit that referenced this issue Dec 12, 2022
@GitMensch
Copy link
Contributor Author

Do you have any insights how to add own syntax definitions for the AppImage? It seems just placing xml files in $HOME/.local/share/org.kde.syntax-highlighting/syntax/ is not enough.

@lievenhey lievenhey reopened this Jan 10, 2023
@lievenhey
Copy link
Contributor

on my pc the definition files are in /usr/share/org.kde.syntax-highlighting/syntax-bundled. I can add an option for custom search paths in that case.

@GitMensch
Copy link
Contributor Author

on my pc the definition files are in /usr/share/org.kde.syntax-highlighting/syntax-bundled. I can add an option for custom search paths in that case.

That would be very useful, especially for AppImage users who may not be able to write to this folder.
Thank you very much!

@milianw
Copy link
Member

milianw commented Jan 11, 2023

please also first strace the appimage (after extracting it with --appimage-extract to figure out why it's not picking up that folder by default, I see no reason why that would happen?

@GitMensch
Copy link
Contributor Author

GitMensch commented Jan 11, 2023

OK, checked with strace and see that the following folders are searched:

stat("/home/me/.local/share/org.kde.syntax-highlighting/syntax", 0x7fffa0ddc2b0) = -1 ENOENT (No such file or directory)
stat("/usr/local/share/org.kde.syntax-highlighting/syntax", 0x7fffa0ddc2b0) = -1 ENOENT (No such file or directory)
stat("/usr/share/org.kde.syntax-highlighting/syntax", 0x7fffa0ddc2b0) = -1 ENOENT (No such file or directory)
stat("/home/me/.local/share/katepart5/syntax", 0x7fffa0ddc2b0) = -1 ENOENT (No such file or directory)
stat("/usr/local/share/katepart5/syntax", 0x7fffa0ddc2b0) = -1 ENOENT (No such file or directory)
stat("/usr/share/katepart5/syntax", 0x7fffa0ddc2b0) = -1 ENOENT (No such file or directory)
stat("/home/me/.local/share/org.kde.syntax-highlighting/themes", 0x7fffa0ddc2b0) = -1 ENOENT (No such file or directory)
stat("/usr/local/share/org.kde.syntax-highlighting/themes", 0x7fffa0ddc2b0) = -1 ENOENT (No such file or directory)
stat("/usr/share/org.kde.syntax-highlighting/themes", 0x7fffa0ddc2b0) = -1 ENOENT (No such file or directory)

Placing fresh files files from https://invent.kde.org/frameworks/syntax-highlighting/-/tree/master/data/syntax to $HOME/.local/share/org.kde.syntax-highlighting/syntax/ does work fine; both with the extracted appimage and the appimage itself, checked with RedHat and Debian based systems.

I therefore consider nearly everything done here, the only part missing is the documentation (for the source code window in general [edit: that will be added with b6ad55d]).
As soon as this is added to the README a note for "how to adjust the syntax highlighting" could include a hint for placing files to $HOME/.local/share/org.kde.syntax-highlighting/syntax/ and maybe where to get those from.

@milianw
Copy link
Member

milianw commented Jan 12, 2023

I don't quite get why one would want to edit the syntax files or provide custom ones?

@GitMensch
Copy link
Contributor Author

GitMensch commented Jan 12, 2023 via email

@milianw
Copy link
Member

milianw commented Jan 12, 2023

that's the real issue then - our ktexteditor that we bundle in the appimage should come with the up2date syntax declarations embedded as Qt resource files. if that's not working, then this is what should be fixed instead.

@GitMensch
Copy link
Contributor Author

GitMensch commented Jan 12, 2023

that's the real issue then - our ktexteditor that we bundle in the appimage should come with the up2date syntax declarations embedded as Qt resource files. if that's not working, then this is what should be fixed instead.

Hm, where does it get those from and where are the QT resource files in the appimage?

@milianw
Copy link
Member

milianw commented Jan 17, 2023

see https://invent.kde.org/frameworks/syntax-highlighting/-/blob/master/data/CMakeLists.txt

the resource files are compiled directly into the code, in this case the syntax highlighting library from kde frameworks

@GitMensch
Copy link
Contributor Author

Thanks for the reference - does the AppImage uses master or a tag?

@milianw
Copy link
Member

milianw commented Jan 17, 2023

master at the time I last built the docker image, see https://github.com/KDAB/hotspot/blob/master/scripts/appimage/Dockerfile

@GitMensch
Copy link
Contributor Author

Works fine.

@GitMensch
Copy link
Contributor Author

Hm, used the current appimage (from yesterday) on a RHEL7 machine (directly starting it), result: the syntax files were outdated (newer ones missing). To get those working I needed to manually get them as xml files and place it it the right (previously not existing) folder under $HOME, restart - new files available...
Are all xml files generated into the highlighting library?

And related (may be moved out to a separate issue): wouldn't it be useful to manually kick entries out of the list that are not executable (yaml, json, ... there are a bunch of those).

@milianw
Copy link
Member

milianw commented Oct 1, 2023

@GitMensch please create a new task to track that. we might be missing some special flag when compiling the kf5 syntax highlighting framework to embed the data as RCC, unsure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants