Skip to content

Commit 0916bae

Browse files
refactor: Move project name/version logic to Indexer
No functional change intended.
1 parent 5c02051 commit 0916bae

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

packages/pyright-scip/src/indexer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as child_process from 'child_process';
12
import * as path from 'path';
23
import { Event } from 'vscode-languageserver/lib/common/api';
34

@@ -40,6 +41,15 @@ export class Indexer {
4041
// private _getConfigOptions(host: Host, commandLineOptions: CommandLineOptions): ConfigOptions {
4142
let fs = new PyrightFileSystem(createFromRealFileSystem());
4243

44+
// TODO: Use setup.py/pyproject.toml to determine project name and version
45+
if (!scipConfig.projectVersion || scipConfig.projectVersion === '') {
46+
try {
47+
scipConfig.projectVersion = child_process.execSync('git rev-parse HEAD').toString().trim();
48+
} catch (e) {
49+
scipConfig.projectVersion = '';
50+
}
51+
}
52+
4353
let config = new ScipPyrightConfig(scipConfig, fs);
4454
this.pyrightConfig = config.getConfigOptions();
4555

packages/pyright-scip/src/main-impl.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3-
import * as child_process from 'child_process';
43

54
import { scip } from './scip';
65
import { diffSnapshot, formatSnapshot, writeSnapshot } from './lib';
@@ -24,39 +23,22 @@ function indexAction(options: IndexOptions): void {
2423
const projectRoot = workspaceRoot;
2524
process.chdir(workspaceRoot);
2625

27-
// TODO: use setup.py / poetry to determine better projectName
28-
const projectName = options.projectName;
29-
30-
// TODO: Use setup.py / poetry to determine better projectVersion
31-
// for now, the current hash works OK
32-
let projectVersion = options.projectVersion;
33-
if (!projectVersion || projectVersion === '') {
34-
// Default to current git hash
35-
try {
36-
projectVersion = child_process.execSync('git rev-parse HEAD').toString().trim();
37-
} catch (e) {
38-
projectVersion = '';
39-
}
40-
}
41-
4226
const outputFile = path.join(projectRoot, options.output);
4327
const output = fs.openSync(outputFile, 'w');
4428

45-
sendStatus(`Indexing ${projectRoot} with version ${projectVersion}`);
46-
4729
try {
4830
let indexer = new Indexer({
4931
...options,
5032
workspaceRoot,
5133
projectRoot,
52-
projectName,
53-
projectVersion,
5434
environment,
5535
writeIndex: (partialIndex: scip.Index): void => {
5636
fs.writeSync(output, partialIndex.serializeBinary());
5737
},
5838
});
5939

40+
sendStatus(`Indexing ${projectRoot} with version ${indexer.scipConfig.projectVersion}`);
41+
6042
indexer.index();
6143
} catch (e) {
6244
console.warn(
@@ -95,8 +77,6 @@ function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void {
9577
}
9678

9779
console.log('... Snapshotting ... ');
98-
const projectName = options.projectName;
99-
const projectVersion = options.projectVersion;
10080
const environment = options.environment ? path.resolve(options.environment) : undefined;
10181

10282
const snapshotOnly = options.only;
@@ -127,8 +107,6 @@ function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void {
127107
...options,
128108
workspaceRoot: projectRoot,
129109
projectRoot,
130-
projectName,
131-
projectVersion,
132110
environment,
133111
writeIndex: (partialIndex: any): void => {
134112
fs.writeSync(output, partialIndex.serializeBinary());

0 commit comments

Comments
 (0)