10000 fixup: Remove console.log and add more infomration (#29) · sourcegraph/scip-python@cd389ea · GitHub
[go: up one dir, main page]

Skip to content

Commit cd389ea

Browse files
authored
fixup: Remove console.log and add more infomration (#29)
1 parent 466640f commit cd389ea

File tree

4 files changed

+46
-47
lines changed

4 files changed

+46
-47
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Project is primarily an addition to Pyright. At this time, there are no substant
77
## Pre-requisites
88

99
```
10+
$ # Install lsif-python
11+
$ npm install -g @sourcegraph/lsif-python
12+
1013
$ # Install and add `lsif-typed` to your path and/or project
1114
$ curl -Lo lsif-typed https://github.com/sourcegraph/lsif-typescript/releases/download/v0.1.8/lsif-typed && chmod +x lsif-typed
1215
```
@@ -16,7 +19,7 @@ $ curl -Lo lsif-typed https://github.com/sourcegraph/lsif-typescript/releases/do
1619
```
1720
$ npm install @sourcegraph/lsif-python
1821
19-
$ # Activate your virtual environment before running
22+
$ # NOTE: make sure to activate your virtual environment before running
2023
$ lsif-python index . --projectName $MY_PROJECT
2124
2225
$ # Transform lsif-python output to traditional LSIF format
@@ -27,3 +30,27 @@ $ # Make sure to point towards the sourcegraph instance you're interested in upl
2730
$ # more information at https://github.com/sourcegraph/src-cli
2831
$ src lsif upload
2932
```
33+
34+
## Sourcegraph Example Configuration
35+
36+
```
37+
{
38+
"index_jobs": [
39+
{
40+
"indexer": "nikolaik/python-nodejs",
41+
"local_steps": [
42+
"curl -Lo lsif-typed https://github.com/sourcegraph/lsif-typescript/releases/download/v0.1.13/lsif-typed",
43+
"chmod +x ./lsif-typed",
44+
"npm install -g @sourcegraph/lsif-python",
45+
"lsif-python index . --projectName tjdevries-sam --projectVersion 0.1",
46+
"./lsif-typed dump.lsif-typed > dump.lsif",
47+
],
48+
"indexer_args": [],
49+
"steps": [],
50+
"outfile": "",
51+
"root": ""
52+
}
53+
],
54+
"shared_steps": []
55+
}
56+
```

packages/pyright-lsif/src/lsif.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-nocheck
2+
13
/**
24
* Generated by the protoc-gen-ts. DO NOT EDIT!
35
* compiler version: 3.17.3
@@ -182,7 +184,7 @@ export namespace lib.codeintel.lsiftyped {
182184
serializeBinary(): Uint8Array {
183185
return this.serialize();
184186
}
185-
static override deserializeBinary(bytes: Uint8Array): Index {
187+
static deserializeBinary(bytes: Uint8Array): Index {
186188
return Index.deserialize(bytes);
187189
}
188190
}
@@ -317,7 +319,7 @@ export namespace lib.codeintel.lsiftyped {
317319
serializeBinary(): Uint8Array {
318320
return this.serialize();
319321
}
320-
static override deserializeBinary(bytes: Uint8Array): Metadata {
322+
static deserializeBinary(bytes: Uint8Array): Metadata {
321323
return Metadata.deserialize(bytes);
322324
}
323325
}
@@ -429,7 +431,7 @@ export namespace lib.codeintel.lsiftyped {
429431
serializeBinary(): Uint8Array {
430432
return this.serialize();
431433
}
432-
static override deserializeBinary(bytes: Uint8Array): ToolInfo {
434+
static deserializeBinary(bytes: Uint8Array): ToolInfo {
433435
return ToolInfo.deserialize(bytes);
434436
}
435437
}
@@ -541,7 +543,7 @@ export namespace lib.codeintel.lsiftyped {
541543
serializeBinary(): Uint8Array {
542544
return this.serialize();
543545
}
544-
static override deserializeBinary(bytes: Uint8Array): Document {
546+
static deserializeBinary(bytes: Uint8Array): Document {
545547
return Document.deserialize(bytes);
546548
}
547549
}
@@ -653,7 +655,7 @@ export namespace lib.codeintel.lsiftyped {
653655
serializeBinary(): Uint8Array {
654656
return this.serialize();
655657
}
656-
static override deserializeBinary(bytes: Uint8Array): Symbol {
658+
static deserializeBinary(bytes: Uint8Array): Symbol {
657659
return Symbol.deserialize(bytes);
658660
}
659661
}
@@ -765,7 +767,7 @@ export namespace lib.codeintel.lsiftyped {
765767
serializeBinary(): Uint8Array {
766768
return this.serialize();
767769
}
768-
static override deserializeBinary(bytes: Uint8Array): Package {
770+
static deserializeBinary(bytes: Uint8Array): Package {
769771
return Package.deserialize(bytes);
770772
}
771773
}
@@ -877,7 +879,7 @@ export namespace lib.codeintel.lsiftyped {
877879
serializeBinary(): Uint8Array {
878880
return this.serialize();
879881
}
880-
static override deserializeBinary(bytes: Uint8Array): Descriptor {
882+
static deserializeBinary(bytes: Uint8Array): Descriptor {
881883
return Descriptor.deserialize(bytes);
882884
}
883885
}
@@ -904,7 +906,7 @@ export namespace lib.codeintel.lsiftyped {
904906
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [3, 4], []);
905907
if (!Array.isArray(data) && typeof data == "object") {
906908
if ("symbol" in data && data.symbol != undefined) {
907-
this.symbol = data.symbol.trimEnd();
909+
this.symbol = data.symbol;
908910
}
909911
if ("documentation" in data && data.documentation != undefined) {
910912
this.documentation = data.documentation;
@@ -1002,7 +1004,7 @@ export namespace lib.codeintel.lsiftyped {
10021004
serializeBinary(): Uint8Array {
10031005
return this.serialize();
10041006
}
1005-
static override deserializeBinary(bytes: Uint8Array): SymbolInformation {
1007+
static deserializeBinary(bytes: Uint8Array): SymbolInformation {
10061008
return SymbolInformation.deserialize(bytes);
10071009
}
10081010
}
@@ -1137,7 +1139,7 @@ export namespace lib.codeintel.lsiftyped {
11371139
serializeBinary(): Uint8Array {
11381140
return this.serialize();
11391141
}
1140-
static override deserializeBinary(bytes: Uint8Array): Relationship {
1142+
static deserializeBinary(bytes: Uint8Array): Relationship {
11411143
return Relationship.deserialize(bytes);
11421144
}
11431145
}
@@ -1157,7 +1159,7 @@ export namespace lib.codeintel.lsiftyped {
11571159
this.range = data.range;
11581160
}
11591161
if ("symbol" in data && data.symbol != undefined) {
1160-
this.symbol = data.symbol.trimEnd();
1162+
this.symbol = data.symbol;
11611163
}
11621164
if ("symbol_roles" in data && data.symbol_roles != undefined) {
11631165
this.symbol_roles = data.symbol_roles;
@@ -1318,7 +1320,7 @@ export namespace lib.codeintel.lsiftyped {
13181320
serializeBinary(): Uint8Array {
13191321
return this.serialize();
13201322
}
1321-
static override deserializeBinary(bytes: Uint8Array): Occurrence {
1323+
static deserializeBinary(bytes: Uint8Array): Occurrence {
13221324
return Occurrence.deserialize(bytes);
13231325
}
13241326
}
@@ -1476,7 +1478,7 @@ export namespace lib.codeintel.lsiftyped {
14761478
serializeBinary(): Uint8Array {
14771479
return this.serialize();
14781480
}
1479-
static override deserializeBinary(bytes: Uint8Array): Diagnostic {
1481+
static deserializeBinary(bytes: Uint8Array): Diagnostic {
14801482
return Diagnostic.deserialize(bytes);
14811483
}
14821484
}

packages/pyright-lsif/src/treeVisitor.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,14 @@ export class TreeVisitor extends ParseTreeWalker {
332332
override visitImport(node: ImportNode): boolean {
333333
this._docstringWriter.visitImport(node);
334334

335+
// TODO(0.2): Resolve all these weird import things.
335336
for (const listNode of node.list) {
336337
let lastName = listNode.module.nameParts[listNode.module.nameParts.length - 1];
337338
let decls = this.evaluator.getDeclarationsForNameNode(lastName);
338339
if (!decls || decls.length === 0) {
339340
continue;
340341
}
341342

342-
console.log('decl node:', decls);
343343

344344
let decl = decls[0];
345345
let filepath = path.resolve(decl.path);
@@ -375,7 +375,6 @@ export class TreeVisitor extends ParseTreeWalker {
375375
// let importName = listNode.module.nameParts[listNode.module.nameParts.length - 1];
376376
// let resolved = this.evaluator.resolveAliasDeclaration(decls[0], true, true);
377377
// let resolvedInfo = this.evaluator.resolveAliasDeclarationWithInfo(decls[0], true, true);
378-
// console.log(resolvedInfo)
379378
}
380379

381380
return true;
@@ -387,14 +386,9 @@ export class TreeVisitor extends ParseTreeWalker {
387386
// this.pushNewNameNodeOccurence(node.module.nameParts[0], LsifSymbol.local(this.counter.next()));
388387
// const decl = this.evaluator.getDeclarationsForNameNode(node.module.nameParts[0])![0]
389388
// const resolvedDecl = this.evaluator.resolveAliasDeclaration(decl, /* resolveLocalNames */ true);
390-
// console.log('decl:', decl);
391-
// console.log(resolvedDecl)
392-
// console.log('type:', this.evaluator.getTypeForDeclaration(decl))
393389
// const moduleName = node.module.nameParts.map(name => name.value).join('.');
394390
// const importedModuleType = ModuleType.create(moduleName, decl.path);
395-
// console.log('modu:', importedModuleType)
396391
// @ts-ignore
397-
// console.log('docs:', getModuleDocString(importedModuleType, decl, this.program._createSourceMapper(this._execEnv)));
398392
// getModuleDocString(ModuleType.create(node.module.nameParts[0].value,
399393

400394
const role = lsiftyped.SymbolRole.ReadAccess;
@@ -714,11 +708,11 @@ export class TreeVisitor extends ParseTreeWalker {
714708
return symbols.pythonModule(this, node, info.importName);
715709

716710
case ParseNodeType.ImportFrom:
717-
// console.log('from', node);
711+
// TODO(0.2): Resolve all these weird import things.
718712
return LsifSymbol.empty();
719713

720714
case ParseNodeType.ImportFromAs:
721-
// console.log('from as', node);
715+
// TODO(0.2): Resolve all these weird import things.
722716
return LsifSymbol.empty();
723717

724718
case ParseNodeType.Lambda:

packages/pyright-lsif/src/virtualenv/PythonEnvironment.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ export default class PythonEnvironment {
55
/// Maps a module name (x.y.z) to an index in this.packages
66
private _moduleNameToIndex: Map<string, number>;
77
private _filepathToIndex: Map<string, number>;
8-
private _cwd: string;
98

109
constructor(private projectVersion: string, public packages: PythonPackage[]) {
11-
this._cwd = path.resolve(process.cwd());
1210
this._moduleNameToIndex = new Map();
1311
this._filepathToIndex = new Map();
1412

@@ -20,13 +18,6 @@ export default class PythonEnvironment {
2018
}
2119
}
2220

23-
private _isThirdPartyFilepath(filepath: string): boolean {
24-
// We just only want files that are from this directory
25-
// dunno if this is the best way to check it yet, but that's what I want to think
26-
// basically.
27-
return path.resolve(filepath).includes(this._cwd);
28-
}
29-
3021
public getPackageForModule(moduleName: string): PythonPackage | undefined {
3122
// TODO: Could turn these into a Set (normalize all paths, replace with `.`, etc) and then just look this up
3223
// that is probably worth it as an optimization later.
@@ -68,19 +59,4 @@ export default class PythonEnvironment {
6859

6960
return this.packages[packageIndex];
7061
}
71-
72-
public getPackageForFile(filepath: string): PythonPackage | undefined {
73-
if (this._isThirdPartyFilepath(filepath)) {
74-
// return { name: '', version: this.projectVersion };
75-
console.log('OK OK');
76-
return new PythonPackage('', this.projectVersion, []);
77-
}
78-
79-
let index = this._filepathToIndex.get(filepath);
80-
if (!index) {
81-
return undefined;
82-
}
83-
84-
return this.packages[index];
85-
}
8662
}

0 commit comments

Comments
 (0)
0