Skip to content

[atom] Use inline documentation for types in grammar-registry.d.ts#56369

Closed
icecream17 wants to merge 7 commits intoDefinitelyTyped:masterfrom
icecream17:icecream17-fix-atom-docs-oops
Closed

[atom] Use inline documentation for types in grammar-registry.d.ts#56369
icecream17 wants to merge 7 commits intoDefinitelyTyped:masterfrom
icecream17:icecream17-fix-atom-docs-oops

Conversation

@icecream17
Copy link

@icecream17 icecream17 commented Oct 7, 2021

Select one of these and delete the others:

If changing an existing definition:

Details

Fixes the problem mentioned here: #56297

The docs for GrammarRegistry point to https://github.com/atom/first-mate/blob/v7.4.1/src/grammar-registry.coffee instead of https://github.com/atom/atom/blob/v1.40.0/src/grammar-registry.js

(Issue in docs repo: atom/flight-manual.atom.io#736)
(Types: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/atom/src/grammar-registry.d.ts)
(Code: https://github.com/atom/atom/blob/v1.40.0/src/grammar-registry.js)

Unfortunately, the types for Atom seem to be based on what the docs say instead of what the code says (understandable).

I didn't remove undocumented methods or add deprecated methods for now. (Although if it should be otherwise let me know.)
Sometimes the docs and the code don't match up. When that happens I explain in the commit

Blocked

steven nguyen added 3 commits October 7, 2021 12:00
See DefinitelyTyped#56297
I didn't remove undocumented methods or add deprecated methods for now.

For `addInjectionPoint` I'm not really sure what "syntax node" refers to. See atom/atom#23019
atom/atom@37a3ae1 might help, although the file has changed since then to only use 1 param: https://github.com/atom/atom/blame/v1.40.0/spec/tree-sitter-language-mode-spec.js. I can't find anything with "node.child".


For `getAssignedLanguageId`, if you look in the code, it's just a `Map#get` call.
Which could be undefined. Now if you look even closer, `assignLanguageMode` and `assignGrammar` also set values to null: https://github.com/atom/atom/blob/v1.40.0/src/grammar-registry.js#L137

So `getAssignedLanguageId` actually returns `undefined | null | string`. But for now, I'm sticking to the documentation in the code

`readGrammar` either calls the callback with `null, Grammar` or `error`. I guess the docs treat `undefined` as equivalent to `null`. But I'm changing the docs anyway.
`getGrammars` docs say "options" but the param is actually called "params".
@icecream17
Copy link
Author

icecream17 commented Oct 7, 2021

I just figured out what SyntaxNode is: https://github.com/tree-sitter/tree-sitter/blob/0e26fbe5e6d74b178b4f4b3ac318e2851bb0019b/lib/binding_web/tree-sitter-web.d.ts#L57

How do I import that? (edit: nvm)

Copy link
Contributor

@lierdakil lierdakil left a comment

Choose a reason for hiding this comment

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

Sorry I've let this sit for a month. I'm sure you're not interested in excuses, but I've had some annoying health problems for the past three weeks or so, which made it really hard to do much beyond necessity.

Anyway, this overall looks good to me, but any is really a misfeature, I strongly believe we should avoid that.

@@ -1,5 +1,12 @@
import { Disposable, Grammar, GrammarToken, TextBuffer } from '../index';

type SyntaxNode = any;
Copy link
Contributor

Choose a reason for hiding this comment

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

CI complains about this, and I really don't like this either, because any opens a gaping hole in the type system, essentially, anything with any isn't typechecked.

I think we can do better: define an empty interface SyntaxNode. Consumers then can extend it in case they need to do something with syntax nodes beyond passing them around.

@lierdakil
Copy link
Contributor

Also, remember that we not only have tree-sitter grammars but textmate grammars too. SyntaxNode will be different for those, I believe (but I didn't check)

@icecream17
Copy link
Author

icecream17 commented Nov 7, 2021

SyntaxNode comes from here: https://github.com/tree-sitter/tree-sitter/blob/0e26fbe5e6d74b178b4f4b3ac318e2851bb0019b/lib/binding_web/tree-sitter-web.d.ts#L57
and microsoft/DefinitelyTyped-tools#333 was just merged so maybe we could import that external typing somehow. I'm not sure what the textmate syntax nodes could be - I couldn't find anything in the code for the types

Steven Nguyen added 2 commits May 5, 2022 17:38
When applying the empty interface suggestion, I ran into the ci lint error:
```ERROR: 3:11  no-empty-interface  An empty interface is equivalent to `{}`.```
@icecream17
Copy link
Author

icecream17 commented May 5, 2022

  1. just saw that comment about textmate grammars
  2. just saw that addInjectionPoint is only valid for tree-sitter grammars:
    https://github.com/atom/atom/search?q=addInjectionPoint&type=code
    atom/atom@4d3916f, meaning the empty type is not necessary

@lierdakil
Copy link
Contributor

Considering Atom will be sunset by the end of the year, I wonder if this PR is still relevant. I've personally switched to vscode, so I don't have a stake in this anymore, but if you want to finish up this PR, I'll approve it once CI stops complaining.

@jakebailey jakebailey closed this Mar 1, 2024
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.

4 participants