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

Integrate Language Server Protocol functionality into Code Windows #751

Merged
merged 24 commits into from
Aug 2, 2024

Conversation

falko17
Copy link
Collaborator

@falko17 falko17 commented Jul 27, 2024

This PR integrates LSP-based information and functionality into SEE's code windows. It is the third and final part of my master's thesis implementation.

This PR resolves #686 and it resolves #728.

LSP integration

The following Language Server features have been integrated into Code Windows1:

  • Semantic Tokens: Syntax highlighting has been implemented using the semantic tokens provided by the Language Server. These are "semantic" as they offer slightly more information than usual lexer-based syntax highlighting tools give us. For example, we can render static elements in italics as an additional modifier to their color.
  • Diagnostics are highlighted using the issue highlighting mechanism implemented in Code Smell Integration: Code City Display #369. Hovering over the corresponding diagnostic yields the message associated to it.
    • As part of this, a custom converter has been implemented that converts Markdown text to TextMeshPro rich text. This way, bold elements are rendered bold, monospace segments are rendered in a monospace font, etc. This is also used for the next item.
  • Hover information is shown to the user when they hover above an element in the code window. This most frequently consists of the rendered documentation for the hovered element.
  • Navigation features are available upon right click on any element in the code window. This opens a right click menu where the user can select from "Find references", "Go to declaration", "Go to definition", "Go to implementation", "Show supertypes", and "Show outgoing calls". Note that options are not shown if the Language Server does not support the respective navigation. Upon selecting any of these, a menu opens from which the user can select a target to jump to (unless there is only one option, in which case it will be opened immediately).
    • When holding down the Ctrl button and clicking on an element in the code window, it will jump to the definition of that element, as is customary in many IDEs.
  • Additionally, the bug behind the Call Hierarchy capability not working has been identified. It is due to a bug in the OmniSharp LSP library which has been reported to the upstream repository. A workaround has also been applied to SEE, so the capability works now.

Additional changes

  • Menu entries for all UI menus in SEE now use a char instead of a Sprite, where the character represents a FontAwesome codepoint, in accordance with our new icon system. This makes it much easier to use new icons compared to the old Sprite-based system.
  • In code windows, when navigating to a certain line (either from a code city block or from the LSP navigation), the line number is marked in red to indicate the target line.
  • The tooltip has been improved to be constrained to a maximum size while not becoming bigger than it has to. This effectively leads to soft wrap functionality for the Tooltip, making bigger Tooltips more likely to fit on the screen.
  • A timeout has been added to the DashboardRetriever. By default, it will fail a request after 5 seconds, but this is configurable in the editor.
  • A bug has been fixed that lead to menu entries not being removed properly if the menu is modified.
  • A ReferenceEqualityComparer class has been added from the .NET 5 source code.
  • The existing scanner infrastructure has been heavily refactored to support getting syntax highlighting information both from Antlr and LSP.
  • Where applicable, plain data classes have been converted to records for brevity.
  • Updated to Unity 2022.3.38f1.

Footnotes

  1. Note that all of these features will only be used if the corresponding option in the LSP handler has been enabled.

falko17 added 17 commits June 29, 2024 22:24
This also heavily refactors our existing scanner
infrastructure to accomodate both Antlr based lexers
and LSP-based semantic token providers.
As the latter also support supplying token modifiers,
support for this has been added as well
(e.g., rendering static things in italics).
This can be used to override equality checks to
use reference equality, which can be useful for
e.g. records.
This also improves the tooltip a bit,
by giving it both a minimum and maximum width.
This bug previously occurred if the entries' titles
contained any slashes, as this would induce different
behavior in the Transform.Find method.
This displays a code window for a given path and range,
instead of for a given graph element.
It works by calling the `FittingElements` extension method
on the graph, also implemented in this commit.

This, in turn, finds graph elements matching
the given path and range, ordered by how well
they fit.
To make things easier and less computationally intensive,
we now simply make the line number of the marked line red
instead of marking the whole line with some background color.
This can be triggered by right-clicking any element
in the code window.
This gives us a much easier option of using existing
icons, rather than having to import an image
and convert it to a sprite each time.
It also improves performance a bit.
@falko17 falko17 requested a review from koschke July 27, 2024 18:34
@falko17 falko17 self-assigned this Jul 27, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are a few bad patterns I found which you should check.

Assets/SEE/UI/Window/CodeWindow/DesktopCodeWindow.cs Outdated Show resolved Hide resolved
Assets/SEE/Utils/Markdown/RichTagsMarkdownRenderer.cs Outdated Show resolved Hide resolved
Assets/SEE/Utils/StringExtensions.cs Outdated Show resolved Hide resolved
Copy link
Collaborator

@koschke koschke left a comment

Choose a reason for hiding this comment

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

I have only very minor issues.

Copy link
Collaborator

@koschke koschke left a comment

Choose a reason for hiding this comment

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

All fine now. Ready to merge.

Assets/SEE/Utils/ReferenceEqualityComparer.cs Show resolved Hide resolved
@koschke koschke enabled auto-merge August 2, 2024 13:28
@koschke koschke merged commit 1edc5ba into master Aug 2, 2024
9 checks passed
@koschke koschke deleted the lsp-for-code-windows branch August 5, 2024 10:56
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 this pull request may close these issues.

LSP: Parse Markdown to TextMeshPro rich text tags Implement support for the Language Server Protocol
2 participants