rmosolgo / language-graphql

GraphQL support for Atom text editor
MIT License
57 stars 13 forks source link

Support for string literal comments #21

Open mikevalstar opened 5 years ago

mikevalstar commented 5 years ago

as of graphql 0.12.3 you can now add comments as string literals

"This is a description."
schema {
    query: Query
}

if we could highlight this somehow, maybe even as comments. note: they can be multi line.

rmosolgo commented 5 years ago

Hi! these should be fixed and highlighted like normal strings in 1.0.0 . please share a screenshot if you run into any more trouble.

brendanfalkowski commented 5 years ago

Semi-related, but I used CMD + / to comment some lines in my schema, which inserted #.

It took me about 5 hours to figure out my JSON kept breaking because those aren't parsed as comments anymore, but the syntax highlighting made it seem that way.

I tried tracing the logic for this through here, and it seems this is not coming back from being a non-default feature flag in the parser.

Might be a good idea to disable that in the Atom language because it's pretty confusing to have what look like comments become the bug.

rmosolgo commented 5 years ago

Wow, so you can't even have non-description comments in the SDL? Interesting 😖

Atom lets you tell it how comments work: https://github.com/rmosolgo/language-graphql/blob/master/settings/language-graphql.json#L4 But if # ... is invalid in the SDL, I'm not sure what to put there!

brendanfalkowski commented 5 years ago

I could be totally wrong because I'm more "1 in 1000 depedencies" than "this is my baby" relative to GraphQL, but based on this it seems string literal "comment here" fully replaced # comment here.

https://github.com/graphql/graphql-js/issues/1245

I'm not an Atom extension expert either — hey, I can name most dinosaurs — but maybe change this:

{
  ".source.graphql": {
    "editor": {
      "commentStart": "# "
    }
  }
}

To this?

{
  ".source.graphql": {
    "editor": {
      "commentStart": "\" ",
      "commentEnd: " \""
    }
  }
}
pthrasher commented 5 years ago

@rmosolgo It appears the current docstring syntax requires that every field definition be followed by a comma. That's not required in the spec, and newlines are valid. As such, my current schema sdl files don't use commas for field definitions and that breaks the syntax highlighting when using doc strings.

awilkins commented 5 years ago

Changing line 109 of graphql.json to

      "end": "(?=\\s*(([_A-Za-z][_0-9A-Za-z]*)\\s*(\\(|:)|(})))|\\s*(,|\\n)",

Highlights properly for me (no idea if this gets the scopes right, but not sure they were being used for anything meaningful).

eduardohueso commented 5 years ago

Commas in comments seem to break syntax highlighting after the comma.

shellscape commented 4 years ago

Not sure how to report properly on this, but I'm using the gql tagged template literal and no highlighting is being performed. Here's a snippet that's affected:

const typeDefs = gql`
  """
  String input format MM-DD-YYYY
  """
  scalar DateInput

  input DateRangeInput {
    start: DateInput
    end: DateInput
  }`;

The gql tagged template literal is available as an export in just about every top-level apollo package, so it's pretty widely used.