-
Notifications
You must be signed in to change notification settings - Fork 44
Fix autocomplete suggesting erratically & add more suggestions #866
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
base: development
Are you sure you want to change the base?
Fix autocomplete suggesting erratically & add more suggestions #866
Conversation
## Release notes: product changes ### New features - **Simple graph visualization** We add simple graph visualization. To try it, run a query that returns ConceptRows and select the graph output type. - **Better visual feedback on startup connection, query errors and switching database** Auto-reconnection on startup, query errors, and switching database now all trigger popup notifications in addition to their usual behaviour. ### Bugs fixed - **Correctly render attribute values in log output** - **Fix some buttons having no state change on hover** - **If creating a database fails, show the error** - **Add field validation to database creation dialog** - **Add field validation to connection address** --------- Co-authored-by: Krishnan Govindraj <[email protected]>
❌ Deploy Preview for typedb-studio failed. Why did it fail? →
|
8d72c22
to
9cd1f7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quick self review
@@ -3,6 +3,7 @@ | |||
"version": "3.4.0-ad30523694ad2b07d11ed0a406b3fe3676358705", | |||
"scripts": { | |||
"ng": "ng", | |||
"generate-grammar": "lezer-generator --typeScript src/framework/codemirror-lang-typeql/typeql.grammar -o src/framework/codemirror-lang-typeql/generated/typeql.grammar.generated", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to run this step every time we update the typeql.grammar
file. I should probably add a comment in that file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a rather generic framework for autocomplete. I don't know its limitations.
You should not have to change this file to add new suggestions, just update typeql_suggestions.ts
|
||
static fromDriver(driver: DriverState, database: string): TypeQLAutocompleteSchemaImpl | null { | ||
function runQuery(driver: DriverState, database: string, query: string): ConceptRowAnswer[] { | ||
// todo: Help please alex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexjpwalker , This is the function I don't know how to implement in the current state of studio. Can you sketch me an implementation? (or do it if you think it's faster that way).
return autocompletion({ override: [wrappedAutocomplete] }); | ||
} | ||
|
||
function updateSchemaFromDB(driver: DriverState, database: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this is the function that needs to be called when the user wants to reload the schema
@@ -128,4 +131,6 @@ export class QueryToolComponent implements OnInit, AfterViewInit, OnDestroy { | |||
readonly JSON = JSON; | |||
readonly TypeQL = TypeQL; | |||
readonly linter = otherExampleLinter; | |||
readonly typeqlAutocompleteExtension = typeqlAutocompleteExtension; | |||
readonly codeEditorKeymap = keymap.of([...defaultKeymap, {key: "Alt-Space", run: startCompletion, preventDefault: true}]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this for mac. I couldn't get the default combination to work.
if (res.ok.answerType == "conceptRows" && res.ok.query != null) { | ||
(window as any)._lastQueryAnswers = res.ok.answers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sneak this into the global namespace for testing schema based suggestions.
{ suffixes: [ [tokens.PLAYS] ], suggestions: [ suggestRoleTypeLabelsScoped ] }, | ||
{ suffixes: [ [tokens.RELATES] ], suggestions: [ suggestRoleTypeLabelsUnscoped ] }, | ||
], | ||
// TODO: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything we find missing.
778b45f
to
6d40872
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file will ideally go away and be replaced by the schema state built for the schema tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file will have to be updated to use your state instead of mine.
return autocompletion({ override: [wrappedAutocomplete] }); | ||
} | ||
|
||
function updateSchemaFromDB(schema: Schema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I call this on schema change, Alex?
55561a1
to
c9990bb
Compare
Release notes: product changes
We fix a bug where the suggestions of variables & labels were unpredictable, and implement more suggestions in an extensible, but ad-hoc way.
We enable suggestions based on a datastructure representing the schema, allowing labels to be suggested based on the schema. This is not fully integrated and does not have an effect yet. It can be manually tested.
We add a build step to generate the parser from the grammar into our build system, so the code is properly integrated into studio.
Motivation
Better autocomplete.
Implementation
We walk up the tree till we find a node we want to do a suggestion at. We're provided with a "prefix". This is the union of the direct children of every node on the path from this suggesting node to the node being parsed*. The nodes on the path are excluded.
E.g. If we reach
ClauseMatch
whereClauseMatch { MATCH Patterns }; Pattern { (Pattern SEMICOLON)+ }
on our climb,match $x isa person; $y
, prefix would be[MATCH, Pattern, SEMICOLON, VAR]
.Ideally, we'd be able to partially generate suggestions from the grammar. Lezer provides a grammar for lezer grammar files.
Manually testing the schema-based suggestions
And this in the JS console:
_updateSchemaFromDB(_lastQueryAnswers, _lastQueryAnswers, _lastQueryAnswers)