Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: regression causing the language server to not be runnable in the browser #2530

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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