Skip to content

Commit f2c4640

Browse files
committed
greptile version of scip
1 parent 9478776 commit f2c4640

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# scip-typescript
22

3-
[SCIP](https://github.com/sourcegraph/scip) indexer for TypeScript and JavaScript.
3+
[SCIP](https://github.com/sourcegraph/scip) indexer for TypeScript and JavaScript.\
4+
5+
6+
7+
### Local Build
8+
9+
```sh
10+
npm i
11+
npm run build
12+
```
13+
14+
### Important Files
15+
The contents of `/src/FileIndexer.ts` contains the parsing/mapping of typescript code to the SCIP format.
416

517
## Quick start
618

src/FileIndexer.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export class FileIndexer {
8181
this.document.symbols.push(
8282
new scip.scip.SymbolInformation({
8383
symbol: symbol.value,
84+
kind: scip.scip.SymbolInformation.Kind.Module,
85+
display_name: moduleName,
8486
documentation: ['```ts\nmodule "' + moduleName + '"\n```'],
8587
})
8688
)
@@ -318,6 +320,8 @@ export class FileIndexer {
318320
this.document.symbols.push(
319321
new scip.scip.SymbolInformation({
320322
symbol: symbol.value,
323+
kind: symbolInformationKind(node, sym),
324+
display_name: sym.getName(),
321325
documentation,
322326
relationships: this.relationships(declaration, symbol),
323327
})
@@ -810,6 +814,69 @@ function scriptElementKind(
810814
return ts.ScriptElementKind.unknown
811815
}
812816

817+
/** Maps Typescript Symbol/Node to scip.SymbolInformation.Kind */
818+
function symbolInformationKind(
819+
node: ts.Node,
820+
sym: ts.Symbol
821+
): scip.scip.SymbolInformation.Kind {
822+
const flags = sym.getFlags()
823+
if (flags & ts.SymbolFlags.Class) {
824+
return scip.scip.SymbolInformation.Kind.Class
825+
}
826+
if (flags & ts.SymbolFlags.Interface) {
827+
return scip.scip.SymbolInformation.Kind.Interface
828+
}
829+
if (flags & ts.SymbolFlags.Enum) {
830+
return scip.scip.SymbolInformation.Kind.Enum
831+
}
832+
if (flags & ts.SymbolFlags.EnumMember) {
833+
return scip.scip.SymbolInformation.Kind.EnumMember
834+
}
835+
if (flags & ts.SymbolFlags.TypeAlias) {
836+
return scip.scip.SymbolInformation.Kind.TypeAlias
837+
}
838+
if (flags & ts.SymbolFlags.TypeParameter) {
839+
return scip.scip.SymbolInformation.Kind.TypeParameter
840+
}
841+
if (flags & ts.SymbolFlags.Function) {
842+
return scip.scip.SymbolInformation.Kind.Function
843+
}
844+
if (flags & ts.SymbolFlags.Method) {
845+
return scip.scip.SymbolInformation.Kind.Method
846+
}
847+
if (flags & ts.SymbolFlags.Constructor) {
848+
return scip.scip.SymbolInformation.Kind.Constructor
849+
}
850+
if (flags & ts.SymbolFlags.GetAccessor) {
851+
return scip.scip.SymbolInformation.Kind.Getter
852+
}
853+
if (flags & ts.SymbolFlags.SetAccessor) {
854+
return scip.scip.SymbolInformation.Kind.Setter
855+
}
856+
if (flags & ts.SymbolFlags.Property) {
857+
return scip.scip.SymbolInformation.Kind.Property
858+
}
859+
if (flags & ts.SymbolFlags.Variable) {
860+
return scip.scip.SymbolInformation.Kind.Variable
861+
}
862+
if (flags & ts.SymbolFlags.Module) {
863+
if (flags & ts.SymbolFlags.NamespaceModule) {
864+
return scip.scip.SymbolInformation.Kind.Namespace
865+
}
866+
return scip.scip.SymbolInformation.Kind.Module
867+
}
868+
if (flags & ts.SymbolFlags.Signature) {
869+
return scip.scip.SymbolInformation.Kind.Signature
870+
}
871+
if (flags & ts.SymbolFlags.TypeLiteral) {
872+
return scip.scip.SymbolInformation.Kind.Type
873+
}
874+
if (flags & ts.SymbolFlags.ObjectLiteral) {
875+
return scip.scip.SymbolInformation.Kind.Object
876+
}
877+
return scip.scip.SymbolInformation.Kind.UnspecifiedKind
878+
}
879+
813880
function isEqualOccurrence(
814881
a: scip.scip.Occurrence,
815882
b: scip.scip.Occurrence

0 commit comments

Comments
 (0)