Skip to content

Commit

Permalink
Fix: regression causing the language server to not be runnable in the…
Browse files Browse the repository at this point in the history
… browser (#2530)

fix #2529
  • Loading branch information
timotheeguerin authored Oct 3, 2023
1 parent 845d0d3 commit f33b0fb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/compiler",
"comment": "",
"type": "none"
}
],
"packageName": "@typespec/compiler"
}
11 changes: 5 additions & 6 deletions packages/compiler/src/config/config-to-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string | undefined>;

Expand Down Expand Up @@ -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 = {
Expand All @@ -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,
})
);
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/server/serverlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
});
Expand Down
1 change: 1 addition & 0 deletions packages/samples/src/sample-snapshot-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function defineSampleSnaphotTest(
overrides.emit = config.emit;
}
const [options, diagnostics] = await resolveCompilerOptions(host, {
cwd: process.cwd(),
entrypoint: sample.fullPath,
overrides,
});
Expand Down

0 comments on commit f33b0fb

Please sign in to comment.