AnarchyTools / SublimeAnarchy

SourceKit can crash more than just Xcode
4 stars 0 forks source link

Syntax highlighting #1

Open drewcrawford opened 8 years ago

drewcrawford commented 8 years ago

There's been some discussion about whether this is implemented via SK or with a markup file.

dunkelstern commented 8 years ago

Markup has been committed, have to evaluate the performance of SK though

drewcrawford commented 8 years ago

If you're interested in how to use SK to power this, here's a braindump, while I'm thinking about it

Instrumented Xcode is making requests like this:

sourcekit: [2:sourcekitd_send_request_sync-before:1295: 1.5981] {
  key.request: source.request.editor.open,
  key.name: "IDEIBSwiftAnnotationProvider:/Users/drew/Code/NaOH/NaOH/crypto_box.swift",
  key.sourcetext: "SourceTextGoesHere"
}

output is like

sourcekit: [2:sourcekitd_send_request_sync-after:1295:217.8741] {
  key.offset: 0,
  key.length: 1490,
  key.diagnostic_stage: source.diagnostic.stage.swift.parse,
  key.syntaxmap: [
    {
      key.kind: source.lang.swift.syntaxtype.comment,
      key.offset: 0,
      key.length: 82
    },
    {
      key.kind: source.lang.swift.syntaxtype.comment,
      key.offset: 82,
      key.length: 53
    },
    {
      key.kind: source.lang.swift.syntaxtype.comment,
      key.offset: 135,
      key.length: 67
    },
    {
      key.kind: source.lang.swift.syntaxtype.comment,
      key.offset: 202,
      key.length: 71
    },
    {
      key.kind: source.lang.swift.syntaxtype.comment,
      key.offset: 273,
      key.length: 25
    },
    {
      key.kind: source.lang.swift.syntaxtype.keyword,
      key.offset: 299,
      key.length: 6
    },
    {
      key.kind: source.lang.swift.syntaxtype.identifier,
      key.offset: 306,
      key.length: 10
    },
    {
      key.kind: source.lang.swift.syntaxtype.comment,
      key.offset: 319,
      key.length: 13
    },
    {
      key.kind: source.lang.swift.syntaxtype.keyword,
      key.offset: 332,
      key.length: 9
    },
    {
      key.kind: source.lang.swift.syntaxtype.typeidentifier,
      key.offset: 342,
      key.length: 8
    },

In our code:

  1. In api.py, add a function for editorOpen that takes a sourcetext. See docInfo for an example, but based on Xcode behavior I don't think we need the usual extraArgs etc.
  2. key.name is likely a nop argument (I suspect some key.name must exist but its value does not matter), but try to confirm empirically whether this is relevant
  3. Parse output
  4. ???
  5. Profit
dunkelstern commented 8 years ago

So you'd send the complete source text over to SK for every key press? That doesn't sound like it would perform...

drewcrawford commented 8 years ago

That isn't the issue. SK can parse well faster than a sourcefile every keypress.

The part I'm worried about is how fast ST will accept region updates.

drewcrawford commented 8 years ago

FYI, I implemented an open request in API for other reasons, so that part of the groundwork is now here.