Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Grammar generator mishandles name property with embedded scopes #16

Open
1 task done
lierdakil opened this issue Jan 11, 2018 · 10 comments
Open
1 task done

Grammar generator mishandles name property with embedded scopes #16

lierdakil opened this issue Jan 11, 2018 · 10 comments

Comments

@lierdakil
Copy link

Prerequisites

Description

Grammar generator mis-handles name property with embedded scopes, for example:

"name": "meta.definition.function.ts entity.name.function.ts"

FirstMate can't handle this syntax, and as a result, source span gets the class syntax--meta syntax--definition syntax--function syntax--ts entity syntax--name syntax--function syntax--ts. Notice the naked entity without synax-- prefix there in the middle.

This is brought over from TypeStrong/atom-typescript#1379

Steps to Reproduce

  1. Create TypeScript file with contents
    class SomeClass {
      someMethod() {}
    }
  2. log-cursor-scope on someMethod

Expected behavior:

  • source.ts
  • meta.class.ts
  • meta.method.declaration.ts
  • meta.definition.method.ts
  • entity.name.function.ts

Actual behavior:

  • source.ts
  • meta.class.ts
  • meta.method.declaration.ts
  • meta.definition.method.ts entity.name.function.ts

Reproduces how often: 100%

Versions

[:~] $ atom --version
Atom    : 1.23.1
Electron: 1.6.15
Chrome  : 56.0.2924.87
Node    : 7.4.0
[:~] $ apm --version
apm  1.18.11
npm  3.10.10
node 6.9.5 x64
atom 1.23.1
python 3.4.6
git 2.15.1

Additional Information

See also: microsoft/TypeScript-TmLanguage#545

@Nxt3
Copy link

Nxt3 commented Jan 16, 2018

This also happens with other Typescript scopes: https://discuss.atom.io/t/cant-seem-to-style-element-based-on-cursor-scope/51526

@lierdakil
Copy link
Author

Bump. Is anyone actually responsible for this project at the moment?

@damieng
Copy link
Contributor

damieng commented Feb 7, 2018

@lierdakil The team was on a bug bash and retreat last month so we are somewhat behind on triage.

@lierdakil
Copy link
Author

Any updates?

@damieng
Copy link
Contributor

damieng commented Mar 21, 2018

The grammar comes from upstream and is supposed to work in a variety of editors - from their README;

This repository contains TmLanguage files that are consumed by TypeScript editors and plugins such as Visual Studio Code, The TypeScript Sublime Plugin, Atom TypeScript, and possibly others.

I'm not aware that any other editor can handle spaces in the names correctly besides VSCode so either that upstream repository isn't the one we all want to use after all or they need to consider not closing the issue with "works in VSCode" :(

@lierdakil
Copy link
Author

FWIW, Sublime seems to handle it correctly:
image
while in Atom it's
image
when it should be
image

(I'm not familiar enough with Sublime to make any informed claims, but it seems that it just uses whitespace as a scope delimiter, so if grammar yields a scope with whitespace, Sublime just treats that as two scopes)

@lierdakil
Copy link
Author

Might it might be easier to fix on Atom side?.. At least I believe a quick fix should amount to a single-line change (didn't look at the sources yet though, so allow for a ± couple lines). A "correct" fix might prove to be a bit more involved, but probably not drammatically so.

@damieng
Copy link
Contributor

damieng commented Mar 29, 2018

The problem is if I hack the grammar files here then we're effectively detached from upstream unless we keep remembering to make those changes every time we pull...

Also not sure what the right fix would actually be. Sure they've put multiple grammar scope names in a name but there isn't an Atom-compatible syntax for that so we'd just have to choose one or come up with some kind of combo name.

Open to suggestions or PRs (should probably sync upstream again before anyone bothers with that)

@lierdakil
Copy link
Author

I was more thinking along the lines of patching first-mate to handle scopes with spaces actually.

A technically "correct" fix on the grammar side would be a scope-within-a-scope. So essentially (and forgive me if it doesn't work, it was a while since I last touched grammar)

match: '...'
name: 'meta.definition.function.ts'
captures: 0: name: 'entity.name.function.ts'

... although it isn't nestable, or at least I can't say from the top of my head how it could be.

@lierdakil
Copy link
Author

And by "nestable" I actually meant "can handle more than two scopes". Sorry, long day.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants