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

TargetNamespace.1/2 error range fix #761

Merged

Conversation

datho7561
Copy link
Contributor

@datho7561 datho7561 commented Jun 3, 2020

If the declared namespace of the root element is not the same as
the namespace declared in the schema, the xmlns attribute of the root
element is highlighted.

If there is no namespace declared in the root element, but one is
declared in the schema, the root element is highlighted.

Added a CodeAction attached to TargetNamespace.1 that replaces
the namespace declared in the instance with the namespace declared in
the schema.

Added a CodeAction attached to TargetNamespace.2 that adds the
xmlns attribute to the root element and fills it with the namespace
used in the schema.

Fixes #704, Fixes #703

Signed-off-by: David Thompson [email protected]

@fbricon fbricon requested a review from xorye June 3, 2020 19:33
@fbricon
Copy link
Contributor

fbricon commented Jun 3, 2020

See if you can fix #703 too, as part of this PR

@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch from a70fec4 to 9caf36d Compare June 3, 2020 20:22
@datho7561
Copy link
Contributor Author

@fbricon I'll add a fix for it as well. Should I include the code snippets that were originally mentioned in this PR, or open a separate issue to fix them?

@fbricon
Copy link
Contributor

fbricon commented Jun 3, 2020

Huh which snippets are you referring to?

@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch 2 times, most recently from 1150fea to bc46add Compare June 3, 2020 20:55
@datho7561 datho7561 changed the title TargetNamespace.1 error highlights invalid xmlns TargetNamespace.1/2 error range fix Jun 3, 2020
@datho7561
Copy link
Contributor Author

@fbricon Oops. Sorry, I meant CodeActions. Angelo mentioned adding CodeActions in the issues. Should I make separate issues for these, or add them in this PR?

@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch from bc46add to 676c7d7 Compare June 3, 2020 21:11
@fbricon
Copy link
Contributor

fbricon commented Jun 4, 2020

We'll add code actions separately, in 0.13.0 or later

@fbricon
Copy link
Contributor

fbricon commented Jun 4, 2020

I see you already have 1 code action. We should then have the other one as well, to be consistent. Hopefully it should be fairly straightforward to add now

@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch 2 times, most recently from ea81d9b to 591f66e Compare June 4, 2020 13:16
@datho7561
Copy link
Contributor Author

Still working on the tests for them, but here are demos of the CodeActions:
TargetNamespace 1-fix-declaration
TargetNamespace 2-add-declaration

@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch 2 times, most recently from f3a2451 to 39d5806 Compare June 4, 2020 15:28
@datho7561 datho7561 marked this pull request as ready for review June 4, 2020 15:28
@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch from 39d5806 to 1ec1702 Compare June 4, 2020 15:30
@angelozerr
Copy link
Contributor

Nice demo!

@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch from 1ec1702 to fc7ac7b Compare June 4, 2020 18:58
@datho7561
Copy link
Contributor Author

Nice demo!

Thank you!

@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch from fc7ac7b to c7f9a97 Compare June 4, 2020 19:05
@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch from c7f9a97 to db59752 Compare June 5, 2020 14:19
@angelozerr
Copy link
Contributor

@datho7561 please fix the conflict

@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch from db59752 to d5893e0 Compare June 5, 2020 14:58
@datho7561
Copy link
Contributor Author

datho7561 commented Jun 5, 2020

@datho7561 please fix the conflict

Fixed

// The error message has this form:
// TargetNamespace.1: Expecting namespace 'NaN', but the target namespace of the
// schema document is 'http://two-letter-name'.
Matcher nsMatcher = NAMESPACE_EXTRACTOR.matcher(diagnosticMessage);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My worry is what if the namespace contains a ' (not url encoded like %XX) character?

@angelozerr do we need to worry about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I looked at the specification to see if ' is allowed in a namespace: https://www.w3.org/TR/xml/#NT-Name
My understanding from this document is that it isn't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xerces doesn't complain when you write targetNamespace="'", so I think we should take care of even if it's not a common usecases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it and unit tests for it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented it so that it will work with ' and escapes it when it occurs, but it doesn't recognize the escaped version of ', so it still raises TargetNamespace.1:

DoesntFixErrorQuotes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed the code that implements the above (with tests) into this PR. Right now, it always tries to escape single quotes. I left it as a separate commit in case it we want to revert it. Other options could be:

  • Always use double quotes when declaring xmlns if there is a single quote embedded in the targetNamespace
  • Don't give a code action if single quotes are prefered and there are single quotes in the targetNamespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^This has been reverted back to the code that doesn't deal with single quotes in the namespace

@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch from d5893e0 to ea06c6f Compare June 5, 2020 15:23
@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch 2 times, most recently from 72f8e87 to 1adb388 Compare June 5, 2020 17:11
@datho7561
Copy link
Contributor Author

There are some issues with the build that I don't seem to have on my computer.

@datho7561
Copy link
Contributor Author

I ran the tests under a fresh Fedora 32 VM with openjdk 11, using the included maven wrapper and there were no failed tests.

@angelozerr
Copy link
Contributor

If you repush your branch with amend (to restart the CI build) is it working better?

@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch from 1adb388 to a68a567 Compare June 5, 2020 19:11
@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch 2 times, most recently from f2dfe80 to c30cd98 Compare June 9, 2020 14:18
@datho7561
Copy link
Contributor Author

I've reverted my changes that try to resolve single quotes in the namespace. This PR is ready for review.

If the declared namespace of the root element is not the same as
the namespace declared in the schema, the `xmlns` attribute of the root
element is highlighted.

If there is no namespace declared in the root element, but one is
declared in the schema, the root element is highlighted.

Added a CodeAction attached to `TargetNamespace.1` that replaces
the namespace declared in the instance with the namespace declared in
the schema.

Added a CodeAction attached to `TargetNamespace.2` that adds the
`xmlns` attribute to the root element and fills it with the namespace
used in the schema.

Fixes eclipse-lemminx#704, Fixes eclipse-lemminx#703

Signed-off-by: David Thompson <[email protected]>
@datho7561 datho7561 force-pushed the error-range-target-namespace-1 branch from c30cd98 to 6949126 Compare June 9, 2020 14:34
@xorye xorye merged commit c1aeb8a into eclipse-lemminx:master Jun 9, 2020
@datho7561 datho7561 deleted the error-range-target-namespace-1 branch January 18, 2021 20:36
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 this pull request may close these issues.

Fix error range TargetNamespace.1 Fix error range TargetNamespace.2
4 participants