-
Notifications
You must be signed in to change notification settings - Fork 21
Use unique declaration references #192
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
Conversation
@valerybugakov I think you accidentally committed generated files. I've opened a PR to fix the |
@varungandhi-src, approved your PR 👍 |
Please wait with merging until I've reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@valerybugakov Thank you for this contribution! There are several independent changes in this PR that make it harder to review than necessary. I opened a separate PR #194 to demonstrate how the issue can be fixed with a smaller diff. In the future, I encourage you to try and open separate PRs for independent changes. It's especially important that functional changes like the new ts.isNamespaceImport(node)
condition are documented with a minimized diff in the git history.
@@ -11,8 +11,8 @@ | |||
"tslint": "tslint -p tsconfig.json --format stylish", | |||
"eslint": "eslint --cache '**/*.ts?(x)'", | |||
"build": "node ./node_modules/typescript/bin/tsc -b .", | |||
"test": "uvu -r ts-node/register --ignore dist", | |||
"update-snapshots": "uvu -r ts-node/register --ignore dist --update-snapshots", | |||
"test": "TS_NODE_TRANSPILE_ONLY=true uvu -r ts-node/register --ignore dist", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added new test-fast
and update-snapshots-fast
scripts. I prefer to get the type errors in the terminal because typechecking is reasonably fast in this codebase and debugging runtime exceptions is slower than debugging type errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! To clarify the reasoning behind this: while iterating on changes locally, I often have type errors because I want to test some logic but don't want to invest time into making Typescript happy about it because there's no intent to commit it. Type-checking slows down the process of trying different ideas on existing tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm +1 to adding these scripts to package.json as long as we keep the typechecking variants as well. For sg/sg, I appreciate that sg start
doesn't typecheck because it's a big codebase slowing down the edit/reload/debug feedback loop. In scip-typescript, typechecking has been fast enough for my needs.
if ( | ||
ts.isImportSpecifier(node) || | ||
ts.isImportClause(node) || | ||
ts.isNamespaceImport(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change related to de-duplication? It would be nice to isolate this change and have a diff in the snapshot tests to better understand the exact motivation for this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return [] | ||
} | ||
|
||
return Array.from( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This expression is fairly expensive considering it's in a very hot loop and that we can achieve a similar results with a single if condition, as is done in
#194
It's very important that we try to keep performance parity with tsc -b
and the fewer redundant collections we allocate the better.
const isDefinition = this.declarationName(node.parent) === node | ||
if (isDefinition) { | ||
role |= scip.scip.SymbolRole.Definition | ||
private visitDefinition(node: ts.Node, sym: ts.Symbol): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this refactoring is an improvement in maintainability. In the future, I want to add more symbol roles such as import and write and then the symbol_roles
bitmask will need to be updated in two different places.
@@ -65,7 +65,21 @@ export class FileIndexer { | |||
if (ts.isIdentifier(node) || ts.isStringLiteralLike(node)) { | |||
const sym = this.getTSSymbolAtLocation(node) | |||
if (sym) { | |||
this.visitSymbolOccurrence(node, sym) | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's not super clear why this.declarationName(node.parent) === node
identifies a definition. To improve readability, I'd prefer to add a function private isDefinition(...): boolean
with a docstring than adding an inline comment like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #152
The too many references issue was caused by the fact that
ts
has multiple definitions in the same file, and we used this information to create a reference for eachnamespace ts
block.This PR removes redundant references by filtering out duplicated SCIP symbol values.
This PR also fixes SCIP symbol generation for namespace imports. Covered by the updated snapshot test.
Test plan
See the updated
snapshots/input/syntax/src/namespace.d.ts
spanshot test.