diff --git a/.vscode/settings.json b/.vscode/settings.json index 0809508abc..7068a32abc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,7 +10,8 @@ "docs/spec.html": true, "common/config/rush/pnpm-lock.yaml": true, "**/node_modules/**": true, - "packages/website/versioned_docs/**": true + "packages/website/versioned_docs/**": true, + "packages/samples/scratch/**": false // Those files are in gitignore but we still want to search for them }, "files.exclude": { "**/common/temp/**": true, diff --git a/common/changes/@typespec/compiler/fix-playground-lsp_2023-10-03-15-56.json b/common/changes/@typespec/compiler/fix-playground-lsp_2023-10-03-15-56.json new file mode 100644 index 0000000000..5945164bd2 --- /dev/null +++ b/common/changes/@typespec/compiler/fix-playground-lsp_2023-10-03-15-56.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/compiler", + "comment": "", + "type": "none" + } + ], + "packageName": "@typespec/compiler" +} \ No newline at end of file diff --git a/packages/compiler/src/config/config-to-options.ts b/packages/compiler/src/config/config-to-options.ts index f95a4e76d4..5ad6c58c54 100644 --- a/packages/compiler/src/config/config-to-options.ts +++ b/packages/compiler/src/config/config-to-options.ts @@ -15,14 +15,13 @@ export interface ResolveCompilerOptionsOptions extends ConfigToOptionsOptions { } export interface ConfigToOptionsOptions { - /** Current working directory. This will be used to interpolate `{cwd}` in the config. - * @default to `process.cwd()` + /** + * Current working directory. This will be used to interpolate `{cwd}` in the config. */ - cwd?: string; + cwd: string; /** * Environment variables. - * @default process.env */ env?: Record; @@ -74,7 +73,7 @@ export async function resolveCompilerOptions( * @returns */ export function resolveOptionsFromConfig(config: TypeSpecConfig, options: ConfigToOptionsOptions) { - const cwd = normalizePath(options.cwd ?? process.cwd()); + const cwd = normalizePath(options.cwd); const diagnostics = createDiagnosticCollector(); const configWithOverrides: TypeSpecConfig = { @@ -86,7 +85,7 @@ export function resolveOptionsFromConfig(config: TypeSpecConfig, options: Config expandConfigVariables(configWithOverrides, { cwd, outputDir: options.overrides?.outputDir, - env: options.env ?? process.env, + env: options.env ?? {}, args: options.args, }) ); diff --git a/packages/compiler/src/server/serverlib.ts b/packages/compiler/src/server/serverlib.ts index de6b6f6612..8b25ab671f 100644 --- a/packages/compiler/src/server/serverlib.ts +++ b/packages/compiler/src/server/serverlib.ts @@ -391,7 +391,7 @@ export function createServer(host: ServerHost): Server { const mainFile = await getMainFileForDocument(path); const config = await getConfig(mainFile); - const [optionsFromConfig, _] = resolveOptionsFromConfig(config, {}); + const [optionsFromConfig, _] = resolveOptionsFromConfig(config, { cwd: path }); const options: CompilerOptions = { ...optionsFromConfig, ...serverOptions, diff --git a/packages/compiler/test/config/resolve-compiler-option.test.ts b/packages/compiler/test/config/resolve-compiler-option.test.ts index b42c133dfd..c05c19e848 100644 --- a/packages/compiler/test/config/resolve-compiler-option.test.ts +++ b/packages/compiler/test/config/resolve-compiler-option.test.ts @@ -3,7 +3,7 @@ import { dirname } from "path"; import { fileURLToPath } from "url"; import { resolveCompilerOptions } from "../../src/config/index.js"; import { NodeHost } from "../../src/core/node-host.js"; -import { resolvePath } from "../../src/index.js"; +import { normalizePath, resolvePath } from "../../src/index.js"; import { expectDiagnosticEmpty, expectDiagnostics } from "../../src/testing/expect.js"; const scenarioRoot = resolvePath( @@ -17,6 +17,7 @@ describe("compiler: resolve compiler options", () => { const resolveOptions = async (path: string) => { const fullPath = resolvePath(scenarioRoot, path); return await resolveCompilerOptions(NodeHost, { + cwd: normalizePath(process.cwd()), entrypoint: fullPath, // not really used here configPath: fullPath, }); diff --git a/packages/samples/src/sample-snapshot-testing.ts b/packages/samples/src/sample-snapshot-testing.ts index 352567bafe..aff140112b 100644 --- a/packages/samples/src/sample-snapshot-testing.ts +++ b/packages/samples/src/sample-snapshot-testing.ts @@ -95,6 +95,7 @@ function defineSampleSnaphotTest( overrides.emit = config.emit; } const [options, diagnostics] = await resolveCompilerOptions(host, { + cwd: process.cwd(), entrypoint: sample.fullPath, overrides, });