Skip to content

feat: use KSyntaxHighlighter for code highlighting#1101

Merged
ouuan merged 20 commits intocpeditor:masterfrom
rogeryoungh:ksyntax-highlighting2
Jul 23, 2023
Merged

feat: use KSyntaxHighlighter for code highlighting#1101
ouuan merged 20 commits intocpeditor:masterfrom
rogeryoungh:ksyntax-highlighting2

Conversation

@rogeryoungh
Copy link
Copy Markdown
Contributor

@rogeryoungh rogeryoungh commented Sep 14, 2022

Use Kate's Syntax highlighter engine for Code Highlighting.

Description

This PR is the same as #516, but without FakeVim.

Related Issues / Pull Requests

#516

Motivation and Context

To make syntax highlighting more better.

How Has This Been Tested?

Tested on Arch Linux.

Screenshots (if appropriate)

github looks broken
github looks broken

Checklist

  • If the key of a setting is changed, the old attribute is updated or it is resolved in SettingsUpdater.
  • If there are changes of the text displayed in the UI, they are wrapped in tr() or QCoreApplication::translate().
  • If needed, I have opened a pull request or an issue to update the documentation.
  • If these changes are notable, they are documented in CHANGELOG.md.

@rogeryoungh rogeryoungh changed the title Add KSyntaxHighlighter for code highlighting feat: use KSyntaxHighlighter for code highlighting Sep 14, 2022
@rogeryoungh
Copy link
Copy Markdown
Contributor Author

I have tried running release.yml in my repo and got a lot of errors under Windows.

My guess is that window-latest points to Windows Server 2022 and VS 2022, but 2019 is hardcoded in many places in the build process. Ubuntu may also can be updated to 20.04 or 22.04.

@ouuan
Copy link
Copy Markdown
Member

ouuan commented Sep 14, 2022

My guess is that window-latest points to Windows Server 2022 and VS 2022, but 2019 is hardcoded in many places in the build process.

You may try updating it. It would be preferred if the VS version can be not hardcoded while not adding too much complexity in the scripts.

Ubuntu may also can be updated to 20.04 or 22.04.

linuxdeployqt recommends targeting the oldest still-supported Ubuntu LTS release, which is still 18.04.

@rogeryoungh rogeryoungh mentioned this pull request Sep 15, 2022
4 tasks
@coder3101
Copy link
Copy Markdown
Member

coder3101 commented Sep 15, 2022

There are functions like isPositionInsidexxxx in CodeEditor.cpp which was incomplete in original PR.

The usage would be when highlighting matching parenthesis we will ignore the parenthesis that comes inside comments, single/double quotes or string literals.

Its incomplete here as well.

@stale
Copy link
Copy Markdown

stale bot commented Oct 15, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Inactive issues label Oct 15, 2022
@ouuan ouuan added high_priority High Priority Issues are marked with this label. and removed stale Inactive issues labels Oct 16, 2022
@rogeryoungh
Copy link
Copy Markdown
Contributor Author

I'm trying to use KTextEditor.

Currently, basic editing and highlighting work fine. It looks like Kate is studded.

image

@coder3101
Copy link
Copy Markdown
Member

KTextEditor is nice, If we are able to compile on all platforms. Back in the days, it was not fully cross platform. Now it seems a good choice for us.

@rogeryoungh
Copy link
Copy Markdown
Contributor Author

I recently tried KTextEditor again, referred some code to Kate, and now I can highlight the error line, the text hint is not yet completed, and I guess it will be solved smoothly.

github looks broken

But I'm running into some sticky issues.

  • KTextEditor is bound to some shortcut keys, such as Ctrl+S, Ctrl+F, etc., which cause conflicts with the main window.
  • KTextEditor has its own Cursor, and it is difficult to convert with QTextCursor, which breaks many functions.
  • KTextEditor provides three setting methods, and serialization encountered difficulties.
    1. ConfigInterface, less options.
    2. Editor Config, this component can be embedded in Dialog or Widget. The UI is a bit inconsistent, the language doesn't follow the settings, and Reset doesn't seem to be able to roll back some options.
    3. writeSessionConfig, I haven't tried it, it may be the same as 1 or 2.

To use KTextEditor, we need a massive redesign.

@rogeryoungh rogeryoungh closed this Jun 5, 2023
@rogeryoungh rogeryoungh force-pushed the ksyntax-highlighting2 branch 2 times, most recently from 92ebb8e to 5ef969d Compare June 5, 2023 12:15
@rogeryoungh
Copy link
Copy Markdown
Contributor Author

I fixed the bracket matching code. Refer to the code of Kate to maintain the Attribute of each row in the highlighter. Now we can directly get the style at a certain position to judge whether it is in the string or comment. So isPositionInsidexxxx is no longer needed.

https://github.com/rogeryoungh/cpeditor/blob/ksyntax-highlighting2/src/Editor/CodeEditor.cpp#L736-L754

QtFindReplaceDialog waits for cpeditor/QtFindReplaceDialog#9.

@rogeryoungh rogeryoungh reopened this Jun 5, 2023
@rogeryoungh rogeryoungh force-pushed the ksyntax-highlighting2 branch from 02fee3a to 4b6eb69 Compare June 7, 2023 03:15
@coder3101
Copy link
Copy Markdown
Member

I have reviewed the code, and next will test it. Thanks for all your efforts! 😃

@rogeryoungh rogeryoungh requested a review from coder3101 July 9, 2023 06:05
coder3101
coder3101 previously approved these changes Jul 16, 2023
Copy link
Copy Markdown
Member

@coder3101 coder3101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
Could you please run the release script in your fork and share the release artifact. We could test if all required dependencies are getting bundled

@coder3101
Copy link
Copy Markdown
Member

coder3101 commented Jul 16, 2023

Got it here

@coder3101
Copy link
Copy Markdown
Member

@ouuan can you test on Linux?
Works fine on macOS and Windows.

@coder3101 coder3101 linked an issue Jul 16, 2023 that may be closed by this pull request
5 tasks
This was referenced Jul 16, 2023
@coder3101 coder3101 linked an issue Jul 16, 2023 that may be closed by this pull request
5 tasks
@ouuan
Copy link
Copy Markdown
Member

ouuan commented Jul 16, 2023

It generally works. But see the unchecked items in #516. There are some regressions and unfulfilled enhancements, though not very critical.

@coder3101
Copy link
Copy Markdown
Member

Minor regression is fine, we can iron it out slowly in subsequent PR, as for small unfulfilling requirements, we can list it out in a single issue and fix it.

What do you think @rogeryoungh?

@rogeryoungh
Copy link
Copy Markdown
Contributor Author

rogeryoungh commented Jul 17, 2023

I agree with you.

I found a small problem during the test, the color of the error lines and the current line does not mix well, and it cannot be seen under some themes, I will fix it right away.

before
1689563942827.png
after
1689563903115.png

@coder3101 coder3101 requested a review from ouuan July 23, 2023 03:40
@coder3101
Copy link
Copy Markdown
Member

We can merge this and let alpha version users find and report bugs or regression.

Hope @rogeryoungh will contribute in fixing and triaging them.

@ouuan
Copy link
Copy Markdown
Member

ouuan commented Jul 23, 2023

@allcontributors add @rogeryoungh for code

@cpeditor cpeditor deleted a comment from allcontributors bot Jul 23, 2023
@rogeryoungh rogeryoungh mentioned this pull request Jul 23, 2023
4 tasks
@coder3101 coder3101 mentioned this pull request Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

high_priority High Priority Issues are marked with this label.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more themes Collapse Function Reg: Parenthesis occurence in comments Solarized Dark focus area is not readable Incorrect highlighting

3 participants