-
Notifications
You must be signed in to change notification settings - Fork 268
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
204 support schema associations in file #280
204 support schema associations in file #280
Conversation
4427479
to
f145387
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.
It looks good to me, just a few things to address.
I've also discovered: #286 when testing this PR but its a completely seperate issue
}).then(done, done); | ||
}); | ||
|
||
it('Provide completion from schema declared in file with several attributes', done => { |
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.
Is there any way you can rebase on master and integrate these tests into the main autoCompletion.test.ts file? And also check the actual values of result.items. Also can you add another test for completion with yaml-language-server modelline in multiple documents. I've been trying to harden the tests lately
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 a test with multiple documents. it seems there is no "textEdit" which is added:
(node:25674) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Expected values to be loosely deep-equal:
{
documentation: '',
insertText: 'prop1: $1',
insertTextFormat: 2,
kind: 10,
label: 'prop1'
}
should equal
{
documentation: '',
insertText: 'prop1: $1',
insertTextFormat: 2,
kind: 10,
label: 'prop1',
textEdit: {
newText: 'prop1: $1',
range: {
end: {
character: 2,
line: 0
},
start: {
character: 2,
line: 0
}
}
}
}
I don't get why it woudl be specific to what I changed. I will have a look tomorrow.
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 an existing bug on master #288
I think we can go without checking for the specific completion in this PR given that the completion is well provided and inserted in VS Code yaml anyway.
- association done using modeline "# yaml-language-server: $schema=<mySchemaURL"> Signed-off-by: Aurélien Pupier <[email protected]>
f145387
to
f21d6fc
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.
LGTM! Only one question, can you set the modelline for each specific yaml doc or does setting it once set it globally for the entire file?
@apupier Is there a reason why we can not use a pattern such as |
*/ | ||
private getSchemaFromModeline(doc: any) : string{ | ||
if (doc instanceof SingleYAMLDocument) { | ||
const modelineDeclaration = '# yaml-language-server:'; |
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 if I put 2 spaces between #
and yaml-language-server:
? Do we want it to be this strict?
I wonder if tokenizing the line with something like string.split("/\b\s+(?!$)/");
would result on a more flexible implementation.
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 went to the easiest. it is also easier to read code. (for instance, I don't see the regexp that you provided to fit what is expected but i'm not sure if it is just an example or not)
That's possible to use regular expression. It allows to be more flexible for the users.
Not sure it is really needed.
I propose to report an issue to handle it in a separate PR. because there is the case of the double-space between #
and yaml-language-server
but there is also tabs. and if it is several spaces between the modeline attributes. and surely a bunch of other cases.
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.
string.match(/\S+/g)
would be the way to get non-whitespace and it is a loop from there.
We should build this flexibility because at the current implementation if somebody tries to use the feature and misses a single space we fail silently. Or we can build a way to warn the users of such "syntax" errors when we detect the intention but that is essentially the same implementation.
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 always not so trivial with regexp. \S
is matching also new line and page break Which we don't want here.
that said, given that we are providingline by line, I think we won't have the false-positives thanks to that.
i'm not very concerned for extra-spaces for yaml users, they already choose a language where each space has a meaning.
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.
updated to cover more cases with extra spaces
it is to better match modeline like way of writing it. It allows to separate concerns, to clarify in which context it is expected to be used and also it will be easier to add other possible parameters. That said, technically it is absolutely possible to use directly the notation From a functional point of view, |
you can set one per yaml doc. and it is joining some limitations I thought during the night:
|
…veloper#204 it requires to cast the parameter in 2 places. Signed-off-by: Aurélien Pupier <[email protected]>
Signed-off-by: Aurélien Pupier <[email protected]>
5368bf9
to
a13c6e3
Compare
…at-developer#204 it ensures that the schema is well-applied also on documents with only the schema declaration Signed-off-by: Aurélien Pupier <[email protected]>
the "textEdit" is not provided due to an existing bug on master redhat-developer#288 Signed-off-by: Aurélien Pupier <[email protected]>
…veloper#204 Signed-off-by: Aurélien Pupier <[email protected]>
b87981e
to
de14434
Compare
const schemaMatchs = yamlLanguageServerModeline.match(/\$schema=\S+/g); | ||
if(schemaMatchs !== null && schemaMatchs.length >= 1) { | ||
if (schemaMatchs.length >= 2) { | ||
console.log('Several $schema attributes has been found on the yaml-language-server modeline. The first one will be picked.'); |
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 can I send a notification to the client?
(can be done in a different 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.
This can be fine for now. server.ts binds console.log
and console.error
to the connection.
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.
...have been found...
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.
@apupier Does this support local schema files? I'm trying this: Figured it out |
Choose to use modeline with pattern
# yaml-language-server: $schema=<urlToTheSchema>
Why?
#SCHEMA
for instance is creating an invalid file with current specifications state, so need to move to a comment-like#
$schema
because it is what is used by VS Code for JSON schemabig advantages of allowing defining the schema in the file is that the filename can be whatever is needed. It avoids the requirement of specific file name pattern. It ensures users can use a schema in all IDEs, no need for a specific IDE integration (apart from relying on Yaml Language Server of course).
For instance in OpenShift dev console, there is no way for user to choose the filename. it would allow to add have completion/validation there.