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

File association pattern validation #586

Closed
AlexXuChen opened this issue Aug 18, 2021 · 7 comments · Fixed by #592
Closed

File association pattern validation #586

AlexXuChen opened this issue Aug 18, 2021 · 7 comments · Fixed by #592
Assignees
Milestone

Comments

@AlexXuChen
Copy link
Contributor

AlexXuChen commented Aug 18, 2021

Related to #573.

When a grammar file is associated with an XML document using xml.fileAssociations, we should ensure that the pattern of the XML document file(s) (pattern field) is valid.

For example, when the file association pattern input is accepted:
Screenshot from 2021-08-18 13-55-45
And the text entry is an invalid pattern, no file association similar to the example below should be entered:

{
"pattern": "**/<invalid pattern>.xml",
"systemId": "<some grammar file path>
}

and instead there should be an error thrown with no file association.

@AlexXuChen AlexXuChen changed the title File association grammar path validation File association pattern validation Aug 18, 2021
@angelozerr
Copy link
Contributor

@rgrunber here a demo with the current work:

FileAssociationCodeLensDemo

As you can see in the demo, user can fill the pattern (**/foo2.xml) and if it changes to **/bar.xml, the pattern doesn't match the XML file to bind. This idea of this issue is to validate this file with a custom command on LemMinx side:

@rgrunber rgrunber self-assigned this Aug 20, 2021
rgrunber added a commit to rgrunber/vscode-xml that referenced this issue Sep 3, 2021
- Fixes redhat-developer#586
- Declare command "xml.check.file.pattern" to be used on the server side
  to determine if a given pattern will match any files

Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
@rgrunber
Copy link
Member

rgrunber commented Sep 3, 2021

I just have one general question about this approach. Initially I thought the reason for validation is to confirm that some file in the workspace folder(s) would match the file association pattern when the user is typing it in the wizard, so they don't waste time creating a pattern that matches nothing.

Now I see that the language server can only know about files that are opened, since we're not going to be sending every file Uri over for the validation. In fact our language server doesn't make use of the workspace folder setting from initialize and I think it would even break protocol to have it checking the filesystem.

So @angelozerr, you suggested to just send over the pattern & uri, and confirm that the pattern would match. Is there any reason we want to force this check to happen on the language server ? Even if other clients would be able to use it, it's a simple pattern check, that they could just as easily implement in their own client's wizard validation logic. If it were a more complicated validation, I would completely agree it should be on the language server side to save time, but I'm just curious about whether we draw any distinction on ease of implementation in deciding whether something gets done on the client, or server side.

@angelozerr
Copy link
Contributor

I just have one general question about this approach. Initially I thought the reason for validation is to confirm that some file in the workspace folder(s) would match the file association pattern when the user is typing it in the wizard, so they don't waste time creating a pattern that matches nothing.

Sorry with my bad explanation. The idea is to write file association for the current file which is bound. We provide a default pattern which works but user can change it (to use * for instance inside file name to check another files that the current). When user change this pattern, the match should continue to work for the current file which is bound.

Now I see that the language server can only know about files that are opened, since we're not going to be sending every file Uri over for the validation. In fact our language server doesn't make use of the workspace folder setting from initialize and I think it would even break protocol to have it checking the filesystem.

Yes I think.

deciding whether something gets done on the client, or server side.

The main reason why I would like to this check on server side is that association with xsd/dtd with file association pattern is done on server side. So the check on wizard should be done on server side to share the same checking behavior (TypeScript glob pattern could have a different behavior from Java glob pattern for instance).

@rgrunber
Copy link
Member

rgrunber commented Sep 6, 2021

Ok, makes sense. I will make the necessary changes.

rgrunber added a commit to rgrunber/vscode-xml that referenced this issue Sep 7, 2021
- Fixes redhat-developer#586
- Declare command "xml.check.file.pattern" to be used on the server side
  to determine if a given pattern will match the given file

Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
rgrunber added a commit to rgrunber/vscode-xml that referenced this issue Sep 7, 2021
- Fixes redhat-developer#586
- Declare command "xml.check.file.pattern" to be used on the server side
  to determine if a given pattern will match the given file

Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
@angelozerr angelozerr added this to the 0.18.1 milestone Sep 7, 2021
angelozerr pushed a commit that referenced this issue Sep 7, 2021
- Fixes #586
- Declare command "xml.check.file.pattern" to be used on the server side
  to determine if a given pattern will match the given file

Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
@rgrunber
Copy link
Member

rgrunber commented Sep 7, 2021

@angelozerr Just curious, why did I need to specify ClientCommandConstants.EXECUTE_WORKSPACE_COMMAND in https://github.com/redhat-developer/vscode-xml/blob/master/src/commands/registerCommands.ts#L223 here, but it works find without it here https://github.com/redhat-developer/vscode-xml/blob/master/src/commands/registerCommands.ts#L316 .

@angelozerr
Copy link
Contributor

Just curious, why did I need to specify ClientCommandConstants.EXECUTE_WORKSPACE_COMMAND

It should work without it, no?

@rgrunber
Copy link
Member

rgrunber commented Sep 7, 2021

Just curious, why did I need to specify ClientCommandConstants.EXECUTE_WORKSPACE_COMMAND

It should work without it, no?

When I tried it, I kept getting message:'command 'xml.check.file.pattern' not found'. Adding the above fixed it, but I couldn't figure out why I needed to when other commands didn't.

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 a pull request may close this issue.

3 participants