Skip to content

Commit

Permalink
Don't use Uri.Empty for default workspace. (microsoft#7654)
Browse files Browse the repository at this point in the history
* Don't use Uri.Empty for default workspace.

* addressed PR feedback
  • Loading branch information
heejaechang authored Apr 17, 2024
1 parent 69ded75 commit a8399d3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/analyzer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export class AnalyzerService {
? optionRoot
: isString(optionRoot)
? Uri.file(optionRoot, this.serviceProvider, /* checkRelative */ true)
: Uri.empty();
: Uri.defaultWorkspace(this.serviceProvider);

const executionRoot = this.fs.realCasePath(executionRootUri);
let projectRoot = executionRoot;
Expand Down
17 changes: 12 additions & 5 deletions packages/pyright-internal/src/common/uri/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

import { URI, Utils } from 'vscode-uri';
import { CaseSensitivityDetector } from '../caseSensitivityDetector';
import { isArray } from '../core';
import { combinePaths, isRootedDiskPath, normalizeSlashes } from '../pathUtils';
import { ServiceKeys } from '../serviceKeys';
import { ServiceKey } from '../serviceProvider';
import { FileUri, FileUriSchema } from './fileUri';
import { WebUri } from './webUri';
import { EmptyUri } from './emptyUri';
import { JsonObjType } from './baseUri';
import { isArray } from '../core';
import { ServiceKeys } from '../serviceKeys';
import { ConstantUri } from './constantUri';
import { EmptyUri } from './emptyUri';
import { FileUri, FileUriSchema } from './fileUri';
import { WebUri } from './webUri';

export const enum UriKinds {
file,
Expand Down Expand Up @@ -234,6 +234,13 @@ export namespace Uri {
return EmptyUri.instance;
}

export function defaultWorkspace(serviceProvider: IServiceProvider): Uri;
export function defaultWorkspace(caseSensitivityDetector: CaseSensitivityDetector): Uri;
export function defaultWorkspace(arg: IServiceProvider | CaseSensitivityDetector): Uri {
arg = CaseSensitivityDetector.is(arg) ? arg : arg.get(ServiceKeys.caseSensitivityDetector);
return Uri.file('/<default workspace root>/', arg);
}

export function fromJsonObj(jsonObj: JsonObjType) {
if (isArray<SerializedType>(jsonObj)) {
// Currently only file uri supports SerializedType.
Expand Down
16 changes: 16 additions & 0 deletions packages/pyright-internal/src/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,19 @@ test('verify can serialize config options', () => {
assert.deepEqual(config, deserialized);
assert.ok(deserialized.findExecEnvironment(UriEx.file('foo/bar.py')));
});

test('extra paths on undefined execution root/default workspace', () => {
const nullConsole = new NullConsole();
const service = createAnalyzer(nullConsole);
const commandLineOptions = new CommandLineOptions(undefined, /* fromVsCodeExtension */ false);
commandLineOptions.extraPaths = ['/extraPaths'];

service.setOptions(commandLineOptions);
const configOptions = service.test_getConfigOptions(commandLineOptions);

const expectedExtraPaths = [Uri.file('/extraPaths', service.serviceProvider)];
assert.deepStrictEqual(
configOptions.defaultExtraPaths?.map((u) => u.getFilePath()),
expectedExtraPaths.map((u) => u.getFilePath())
);
});

0 comments on commit a8399d3

Please sign in to comment.