-
Notifications
You must be signed in to change notification settings - Fork 247
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
Datasource Spans & Completions #3703
Conversation
As a note, further changes in the PSL grammar and parsing were necessary due to issues in the formatter. It ended up being simpler to just add the notion of nesting to the rest of the blocks (as opposed to just the configs -- datasource & generator). So, now they all have some form of |
This comment was marked as resolved.
This comment was marked as resolved.
The |
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.
Maybe check the few comments I left?
prisma-fmt/src/get_config.rs
Outdated
let expected = expect![[ | ||
r#"{"message":"\u001b[1;91merror\u001b[0m: \u001b[1mError validating datasource `thedb`: You must provide a nonempty direct URL\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:5\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 4 | \u001b[0m url = env(\"DBURL\")\n\u001b[1;94m 5 | \u001b[0m directUrl = \u001b[1;91m\"\"\u001b[0m\n\u001b[1;94m | \u001b[0m\n\nValidation Error Count: 1","error_code":"P1012"}"# | ||
]]; | ||
let expected = expect![[r#"{"message":"\u001b[1;91merror\u001b[0m: \u001b[1mError validating datasource `thedb`: You must provide a nonempty direct URL\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:5\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 4 | \u001b[0m url = env(\"DBURL\")\n\u001b[1;94m 5 | \u001b[0m \u001b[1;91mdirectUrl = \"\"\u001b[0m\n\u001b[1;94m | \u001b[0m\n\nValidation Error Count: 1","error_code":"P1012"}"#]]; |
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.
You don't need to do this now, but by doing the following:
let response = get_config(&requqest.to_string()).unwrap_err();
let response: serde_json::Value = serde_json::from_str(&response).unwrap();
let response = serde_json::to_string_pretty(&response).unwrap();
The resulting string is having indentation, tabs and all that in place, so it's much nicer to read your expectation when it's not a oneliner.
Maybe a morning PR?
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.
Or, even better, deserialize the result, and assert the different parts. Now you can assert the datamodel a bit like we do in the psl tests, and additionally the error code as a separate assert.
prisma-fmt/tests/text_document_completion/scenarios/datasource_url_arguments/result.json
Outdated
Show resolved
Hide resolved
prisma-fmt/src/get_config.rs
Outdated
let expected = expect![[ | ||
r#"{"message":"\u001b[1;91merror\u001b[0m: \u001b[1mEnvironment variable not found: DOES_NOT_EXIST.\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:5\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 4 | \u001b[0m url = env(\"DBURL\")\n\u001b[1;94m 5 | \u001b[0m directUrl = \u001b[1;91menv(\"DOES_NOT_EXIST\")\u001b[0m\n\u001b[1;94m | \u001b[0m\n\nValidation Error Count: 1","error_code":"P1012"}"# | ||
]]; | ||
let expected = expect![[r#"{"message":"\u001b[1;91merror\u001b[0m: \u001b[1mEnvironment variable not found: DOES_NOT_EXIST.\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:5\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 4 | \u001b[0m url = env(\"DBURL\")\n\u001b[1;94m 5 | \u001b[0m \u001b[1;91mdirectUrl = env(\"DOES_NOT_EXIST\")\u001b[0m\n\u001b[1;94m | \u001b[0m\n\nValidation Error Count: 1","error_code":"P1012"}"#]]; |
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.
The diff in this example is that before only the env(...)
part was one format, and now the whole line it?
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'm honestly not sure how to read the diff here 😅
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.
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 think in prisam/prisma
we use a stripAnsi function to remove the color codes from the messages and snapshot that as well - as it is more readable without breaking your brain)
kind: MarkupKind::Markdown, | ||
value: generate_pretty_doc( | ||
r#""connectionString""#, | ||
r#"Connection URL including authentication info. Each datasource provider documents the URL syntax. Most providers use the syntax provided by the database. [Learn more](https://pris.ly/d/prisma-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.
Duplication with line 92 avoidable?
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.
As an update to url
Connection URL to connect to your database. [Learn more](https://pris.ly/d/connection-strings).
// instead of
Connection URL including authentication info. Each datasource provider documents the URL syntax. Most providers use the syntax provided by the database. [Learn more](https://pris.ly/d/connection-strings).
prisma-fmt/tests/code_actions/scenarios/relation_mode_referential_integrity/result.json
Show resolved
Hide resolved
prisma-fmt/src/validate.rs
Outdated
let expected = expect![[ | ||
r#"{"error_code":"P1012","message":"\u001b[1;91merror\u001b[0m: \u001b[1mThe `referentialIntegrity` and `relationMode` attributes cannot be used together. Please use only `relationMode` instead.\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:6\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 5 | \u001b[0m relationMode = \"prisma\"\n\u001b[1;94m 6 | \u001b[0m \u001b[1;91mreferentialIntegrity = \"foreignKeys\"\u001b[0m\n\u001b[1;94m 7 | \u001b[0m }\n\u001b[1;94m | \u001b[0m\n\nValidation Error Count: 1"}"# | ||
]]; | ||
let expected = expect![[r#"{"error_code":"P1012","message":"\u001b[1;91merror\u001b[0m: \u001b[1mThe `referentialIntegrity` and `relationMode` attributes cannot be used together. Please use only `relationMode` instead.\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:6\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 5 | \u001b[0m relationMode = \"prisma\"\n\u001b[1;94m 6 | \u001b[0m \u001b[1;91mreferentialIntegrity = \"foreignKeys\"\u001b[0m\n\u001b[1;94m | \u001b[0m\n\nValidation Error Count: 1"}"#]]; |
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.
What is the differnece here? Can not figure it out visually.
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.
@@ -132,7 +132,6 @@ fn datasource_should_not_allow_arbitrary_parameters() { | |||
[1;94m | [0m | |||
[1;94m 3 | [0m url = "mysql://localhost" | |||
[1;94m 4 | [0m [1;91mfoo = "bar"[0m | |||
[1;94m 5 | [0m} |
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 additional line of context could in theory contain text and snippets from the schema, and be helpful this way. Did we intentionally remove this?
c21eb86
to
108cad8
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.
Much better already. The specialization of certain completions is something we should have before we merge this. I'm willing to pair about this if needed. Just ping me.
position => ctx.connector().push_completions(ctx.db, position, completion_list), | ||
} | ||
} | ||
|
||
fn ds_has_prop(ctx: CompletionContext<'_>, prop: &str) -> bool { |
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'd implement these directly in the datasource. So, we could ask from datasource ds.schemas_defined()
and so on.
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'm not sure do we really need this. Maybe in a follow-up PR.
This follows the changes for config blocks Co-authored-by: Tom Houlé <13155277+tomhoule@users.noreply.github.com>
Update test expects Co-authored-by: Tom Houlé <13155277+tomhoule@users.noreply.github.com>
new datasource positions
Added: new diagnostic for props without value Co-authored-by: Tom Houlé <13155277+tomhoule@users.noreply.github.com>
Added tests
env -> env() per what was in LT XYZ_URL kind -> 21, per what was in LT db gen > db pull completions no longer re-show-up formatting
- this will need to be re-added later when models and views are updated
Moved extensions and schemas (only postgres). Co-authored-by: Julius de Bruijn <bruijn@prisma.io>
- mssql, mysql, cockroachdb Moved connector completions to builtin-connectors crate
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.
a few things!
position => ctx.connector().push_completions(ctx.db, position, completion_list), | ||
} | ||
} | ||
|
||
fn ds_has_prop(ctx: CompletionContext<'_>, prop: &str) -> bool { |
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'm not sure do we really need this. Maybe in a follow-up PR.
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.
Well done. To production we go!
Changes
Adding datasource completions was necessary as part of this to ensure effective testing. This will require a follow-up PR in language-tools to remove the completions mentioned below from there
Added
datasource
completions ::text_document_completions/datasource.rs
schemas
relationMode
provider
extensions
directUrl
shadowDatabase
url
""
env
XYZ_URL
Completions trigger at start of line
NEWLINE
out of the values i.e.(key_value ~ NEWLINE)
, this has only been done forconfig_block
and will need to be done for the rest laterCompletions only trigger within the bounds (
{}
) of the modelinner_span
in the parser from thexyz_contents
added to the grammarFunc for generating pretty doc for params, see language-tools/completionUtils
format_completion_docs
Specific completions should show before general
Fix other tests
Add tests
Remove "engines" marker from new completions labels
Bugs
Completions shouldn't trigger on the closing line with the
}
on it :: This also existed prior to this PR with the language-tools impl. issueProperty value completions can trigger anywhere after the name, which can be before the
=
sign :: This is an issue withfind_at_position
and would probably require changes in the PEST grammar to include having the=
as an identifiable piece in the parser for config blocks. issueValue completions are available after a value (but not immediately like one space after) -- note, this only seems to affect
url
completions, completions do not show up again on the same line forprovider
,schemas
, andrelationMode
. issue for the followingThis is silly --
XYZ_URL
showing up as a completion within the textenv
but not betweenv
and(
XYZ_URL
shows up as a completion anywhere between the left parenthesis and the character right after)
inenv(...)
Todo
env
&&""
for url, orXYZ_URL
for insideenv
pris.ly
links per internal convolift_datasource
&lift_generator
starting to get a lil unwieldycloses prisma/prisma#17000
Note: This does not entirely fix the issue and is instead a template for future completions additions to engines. This fixes the issue for datasource completions. When, in the future, we add completions to other parts of the schema from engines, this will require similar changes as done here to the PSL.
This is built off the back of the previous pr for adding
schemas
completions.