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

Cleaning and rework for fixing Referencing, Declarations & Usages Search, Renaming, and Syntax Highlighting. #16

Merged
merged 21 commits into from
Feb 27, 2024

Conversation

farost
Copy link
Member

@farost farost commented Feb 26, 2024

Usage and product changes

We fix a number of bugs and frustrating sides of the plugin's logic and UX. Namely:

  • Plugin uses official TypeQL grammar source as a dependency.
  • Default syntax highlighting and coloring now make more sense.
  • Opportunity to import TypeDB Studio's color scheme via several clicks.
  • Overall parsing works better and does not excessively highlight correct code as errors.
  • Referencing is improved, including override constraints like "owns as", "plays as", "relates as".
  • Find Definition and Find Usages work much better and in wider set of cases.
  • Rename feature does not throw exceptions and basically work in most of the cases (still does not work with relations when it is mentioned in "plays": details).
  • Inspection features are disabled until they are stabilized.

Implementation

Details are in the comments, but the overall structure is:

  • High-level TypeQL* files (TypeQLLanguage, TypeQLTokenSets...) describe the language itself. The most interesting and loaded one is TypeQLParserDefinition: it contains logic for creating specific PSI-elements based on the ANTLR output.
  • PSI-elements are declared in the psi package. The entrance here is the base PsiTypeQLElement (basically to distinguish TypeQL tokens from other languages in the tree). Then we have PsiTypeQLStatementType (doesn't have any needed logic for now, so you can ignore it) and two groups of Constraints (implementations are in the constraint package): Named and Referencing elements, which are the basis for Declarations and Usages (read the comments in the Named and Referencing elements' files).
  • Highlighting works with tokens from the parser and is not interested in our PSI-elements. Its details are in the highlighter package.
  • reference package is a continuation of the Named/Referenced elements ballad. Here we specify which elements will work with referencing (TypeQLReferenceContributor) and how our Reference work with some features in details (TypeQLReference).
  • Based on these references, Find Usages/Declarations feature can be activated (usage package). The feature itself is activated in TypeQLFindUsagesProvider, but the main method, which describes the logic behind these buttons, is a part of TypeQLDeclarationFinder (we only need to specify how to find declarations: Find Usages is a derivative operation for us).
  • Refactoring support (refactor package) doesn't contain much logic as it is based on the previous points.
  • Completion (completion package) works good enough, so I leave it as is for now, but I'd like to refactor it in the future, because it's of course not ideal.

In addition to the product changes:

  • A bunch of hardcode has been removed, more to come.
  • There are more parsing test cases in the parsing test for better future control (other tests have not been implemented, we can think about them within the next iteration).

@farost farost marked this pull request as ready for review February 26, 2024 15:40
@farost farost marked this pull request as draft February 26, 2024 16:15
@farost farost marked this pull request as ready for review February 26, 2024 16:16
Copy link
Member Author

@farost farost left a comment

Choose a reason for hiding this comment

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

Self-review finished

gradle.properties Show resolved Hide resolved
companion object {
val INSTANCE: TypeQLLanguage = TypeQLLanguage()
val GRAQL_TYPES: Set<String?> = ImmutableSet.of("attribute", "entity", "relation", "rule", "role", "thing")

// TODO: Move to ParserDefinition and connect with the Parser's tokens
Copy link
Member Author

Choose a reason for hiding this comment

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

Mentioned refactoring todos here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Renaming, all the following "Constraints" are renaming as well.

}
}

fun findDeclarations(
Copy link
Member Author

Choose a reason for hiding this comment

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

That's the whole logic behind finding declarations because of the class structure. I do want to enhance this logic to be smarter (the second part of the issue), but it does work quite well right now.

@farost farost closed this Feb 27, 2024
@farost farost reopened this Feb 27, 2024
@flyingsilverfin flyingsilverfin merged commit 3360d8d into typedb-osi:master Feb 27, 2024
8 checks passed
@farost farost deleted the plugin-reimagined branch February 27, 2024 13:05
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.

2 participants