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

Analyzer plugin for .moor files #150

Closed
simolus3 opened this issue Sep 15, 2019 · 4 comments
Closed

Analyzer plugin for .moor files #150

simolus3 opened this issue Sep 15, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@simolus3
Copy link
Owner

We can write an analyzer plugin for moor files that performs syntax highlighting, folding, outline views, errors, auto-complete, navigation and occurrences on moor files.

(I didn't see an existing issue for the analyzer plugin so feel free to move this as you see fit).
Navigation and syntax highlighting are the first features I'd personally see as most valuable. Being able to ctrl+click on generated dart methods and jump to the .moor file method and vice versa would be so cool - although I get the feeling that's probably the most challenging/complex feature!

Originally posted by @Mike278 in #142 (comment)

@simolus3 simolus3 added the enhancement New feature or request label Sep 15, 2019
@simolus3
Copy link
Owner Author

simolus3 commented Sep 15, 2019

I've started some work on an analyzer plugin that lives in the moor_generator package. Sadly it can't really be previewed yet because no Dart IDE uses the results of the analysis server for custom file endings (the plugin does print some correct-looking outputs in the analysis instrumentation log though). I've opened Dart-Code/Dart-Code#1981 for that, so I hope this looks better in the next VS Code version. I've also opened WEB-41424 for IntelliJ support.

Syntax highlighting

Unfortunately, VS Code plugins can't provide dynamic syntax highlighting. They need to provide a static grammar to VS Code, so the Dart plugin can't use the moor analysis plugin for that. I looks like the IntelliJ plugin can the analysis server for highlighting, so maybe we have more luck there.

Errors

We send both parsing and semantic lints, warnings and errors to the analysis server. Of course, this isn't nearly as helpful as syntax highlighting, but users would get a realtime feedback on invalid queries.

Navigation and occurrences

To reduce complexity, I think it makes sense to first restrict this to sql in moor files only (so you could ctrl + click on a column name inside a query and jump to its definition). As long as the reference appears inside a moor file (and say the column is declared in a Dart file), there shouldn't be problems. Unfortunately, if a plugin sends a navigation event that is different from the Dart analyzer, the analyzer will take priority. So I'm not sure if we can find references to generated methods and "re-route" them to the moor file - the analyzer would probably veto those and link to the .g.dart file.

Autocomplete

I've started some very basic work on this already. Given that we already have a parser, we can use that parsing logic to report an auto-complete option at a specific location. Of course, suggestions that depend on the context (e.g. column names, import files, etc.) would need special work.

Folding and outline

This is arguably least spectacular feature, but at least it's already implemented. We provide information that lets editors collapse some definitions (like the column declarations in a CREATE TABLE statement or the import section). Outline gives an overview of the created tables, which columns they contain and so on in the side bar.

@simolus3
Copy link
Owner Author

With some slight modifications of the Dart extension to VS Code, we can get outline, folding and errors:

Syntax highlighting is blocked by VS Code, but we should be able to get auto-complete, quickfixes and navigation (inside moor files) working.

@simolus3
Copy link
Owner Author

simolus3 commented Oct 4, 2019

Closing this as the prototype has landed in a stable release. Additions should be tracked in other issues.

@simolus3 simolus3 closed this as completed Oct 4, 2019
@Mike278
Copy link
Contributor

Mike278 commented Oct 4, 2019

I discovered a decent workaround for IntelliJ users, but it requires Ultimate edition to have access to the "Database tools and SQL" plugin.

  1. Set the Recognized File Type for .moor files to SQL:
    Recognized File Type

  2. Write the database to a file. For example:

void main() {
  test('create db', () async {
    Database db = Database.withExecutor(VmDatabase(File('todos.sqlite3')));
    await db.categoriesWithCount().first;
  });
}
  1. Add a the file as an sqlite datasource and connect:
    data source

  2. Configure the dialect for the directory as sqlite:
    dialect

Result:
result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants