Skip to content

Treat null as undefined - #128

Closed
Felix Becker (felixfbecker) wants to merge 1 commit into
microsoft:masterfrom
felixfbecker:null-text-edit
Closed

Felix Becker (felixfbecker) wants to merge 1 commit into
microsoft:masterfrom
felixfbecker:null-text-edit

Conversation

@felixfbecker

Copy link
Copy Markdown
Contributor

Fixes #127

@msftclas

Hi Felix Becker (@felixfbecker), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

This seems like a small (but important) contribution, so no Contribution License Agreement is required at this point. Real humans will now evaluate your PR.

TTYL, MSBOT;

1 similar comment
@msftclas

Hi Felix Becker (@felixfbecker), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

This seems like a small (but important) contribution, so no Contribution License Agreement is required at this point. Real humans will now evaluate your PR.

TTYL, MSBOT;

@felixfbecker Felix Becker (felixfbecker) changed the title Check for null in asTextEdit() Treat null as undefined Nov 19, 2016
@dbaeumer

Copy link
Copy Markdown
Member

This is IMO not a correct fix for the problem. If the value is null the property should be present. This is how non JS language work and the protocol defines it that way.

I will look into #127 separately. Any objection to close.

@felixfbecker

Felix Becker (felixfbecker) commented Nov 22, 2016 •

Copy link
Copy Markdown
Contributor Author

If the value is null the property should be present. This is how non JS language work and the protocol defines it that way.

In non-JS languages the protocol structures are typically implemented as a class, and if the property is null, it means the absence of a value.
Maybe I don't understand your set() helper function, but as I understand it, it conditionally calls the provided callback only if the passed value is "there". Your usage suggests that it is used to check first if a value for the property was provided, and only then convert that value to your custom classes. So, if you want to treat null as meaning the absence of a value, just like undefined (you said so here), the set() function should check if the property is null too.

Again - sorry if I misunderstood the use of the helper function, I though this was the most generic way to solve it, because it doesn't only appear with TextEdit, but also with Command etc.

@dbaeumer

Copy link
Copy Markdown
Member

Felix Becker (@felixfbecker) I reworked all this for the upcoming 3.0 release of the node libraries. The set function is gone and I try to be more preceise with null and undefined. I even enable strictNull and documented the API with undefined | null if allowed.

For converting protocol objects into code objects a null value now gets mapped to undefined in this direction since VS Code's API accepts both and it makes the code more clear. However on the protocol layer itself I sometimes explicitly set thing to null if the spec requires this. For example a response must either contain a result or an error. If a request does return undefined in a node server I will set the result to null to honor this.

I will close the PR since the set function is gone.

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.

3 participants