Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scip-typescript produces malformatted symbol whenever there is an invocation of a local class #314

Open
jkoppel opened this issue Jan 23, 2024 · 0 comments
Labels

Comments

@jkoppel
Copy link

jkoppel commented Jan 23, 2024

Whenever there is a locally-defined class whose constructor is invoked, scip-typescript will produce a malformatted symbol. Any downstream consumer of SCIP which is expecting spec-compliant output will break.

Reproducing

Create a directory with a single Typescript file. Call it test-typescript.ts

Set this code.

function foo {
  class Foo {
    constructor() {}
  }
  new Foo();
}

cd to that directory

Add an arbitrary tsconfig.json file

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "rootDir": ".",
    "strict": true
  }
}

Run scip-typescript index

By running scip print on the generated file, we can see that scip-typescript has produced a symbol named "local 0<constructor>().". This is bad because the spec does not permit '(', ')', '<', '>', or '`' to appear in identifiers. https://github.com/sourcegraph/scip/blob/main/scip.proto#L155

        &scip.Occurrence{
          Range: []int32{
            4,
            6,
            9,
          },
          Symbol:                "local 0`<constructor>`().",
          SymbolRoles:           0,
          OverrideDocumentation: []string(nil),
          SyntaxKind:            0,
          Diagnostics:           []*scip.Diagnostic(nil),
          EnclosingRange:        []int32(nil),
        },

Because of this, any spec-complaint downstream consumer will choke.

In particular, the scip snapshot command fails.

(venv) ubuntu@ip-172-31-88-164:~/scip$ go run ./cmd/scip/ snapshot --from test_ts/index.scip
test.ts: use --strict=false to ignore this error: local 0`<constructor>`().: expected format 'local <simple-identifier>' but got: local 0`<constructor>`().
exit status 1

Also, the SCIP-importer in Facebook's Glean chokes.

Related

sourcegraph/scip-python#148

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

No branches or pull requests

2 participants