Skip to content

Commit

Permalink
Use .prettierrc for consistent cross editor experiences
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Jan 17, 2025
1 parent 5659059 commit ef6f3a6
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 22 deletions.
5 changes: 0 additions & 5 deletions editors/code/.editorconfig

This file was deleted.

5 changes: 5 additions & 0 deletions editors/code/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"useTabs": true,
"tabWidth": 4,
"trailingComma": "all"
}
1 change: 1 addition & 0 deletions editors/code/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ out/**
node_modules/**
src/**
.gitignore
.prettierrc
.yarnrc
webpack.config.js
vsc-extension-quickstart.md
Expand Down
6 changes: 3 additions & 3 deletions editors/code/src/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import { AIR_BINARY_NAME, BUNDLED_AIR_EXECUTABLE } from "./constants";
export type ExecutableLocation = "environment" | "bundled";

export async function resolveAirBinaryPath(
executableLocation: ExecutableLocation
executableLocation: ExecutableLocation,
): Promise<string> {
if (!vscode.workspace.isTrusted) {
output.log(
`Workspace is not trusted, using bundled executable: ${BUNDLED_AIR_EXECUTABLE}`
`Workspace is not trusted, using bundled executable: ${BUNDLED_AIR_EXECUTABLE}`,
);
return BUNDLED_AIR_EXECUTABLE;
}

// User requested the bundled air binary
if (executableLocation === "bundled") {
output.log(
`Using bundled executable as requested by \`air.executableLocation\`: ${BUNDLED_AIR_EXECUTABLE}`
`Using bundled executable as requested by \`air.executableLocation\`: ${BUNDLED_AIR_EXECUTABLE}`,
);
return BUNDLED_AIR_EXECUTABLE;
}
Expand Down
2 changes: 1 addition & 1 deletion editors/code/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export const BUNDLED_AIR_EXECUTABLE = path.join(
EXTENSION_ROOT_DIR,
"bundled",
"bin",
AIR_BINARY_NAME
AIR_BINARY_NAME,
);
5 changes: 1 addition & 4 deletions editors/code/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { Lsp } from "./lsp";
// https://github.com/rust-lang/rust-analyzer/blob/master/editors/code/src/ctx.ts

export class Ctx {
constructor(
readonly extension: vscode.ExtensionContext,
public lsp: Lsp,
) {}
constructor(readonly extension: vscode.ExtensionContext, public lsp: Lsp) {}

public getClient(): lc.LanguageClient {
return this.lsp.getClient();
Expand Down
11 changes: 7 additions & 4 deletions editors/code/src/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Lsp {
const initializationOptions = getInitializationOptions("air");

const command = await resolveAirBinaryPath(
workspaceSettings.executableLocation
workspaceSettings.executableLocation,
);

let serverOptions: lc.ServerOptions = {
Expand Down Expand Up @@ -104,7 +104,10 @@ export class Lsp {

const config = vscode.workspace.getConfiguration(
undefined,
{ uri, languageId }
{
uri,
languageId,
},
);
items[i] = config.get(item.section);
}
Expand All @@ -131,10 +134,10 @@ export class Lsp {
"airLanguageServer",
"Air Language Server",
serverOptions,
clientOptions
clientOptions,
);
client.onNotification(SYNC_FILE_SETTINGS, (settings) =>
this.fileSettings.handleSettingsNotification(settings)
this.fileSettings.handleSettingsNotification(settings),
);

await client.start();
Expand Down
10 changes: 5 additions & 5 deletions editors/code/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ export type WorkspaceSettings = {
};

export function getInitializationOptions(
namespace: string
namespace: string,
): InitializationOptions {
const config = getConfiguration(namespace);

return {
logLevel: getOptionalUserValue<LogLevel>(config, "logLevel"),
dependencyLogLevels: getOptionalUserValue<string>(
config,
"dependencyLogLevels"
"dependencyLogLevels",
),
};
}

export function getWorkspaceSettings(
namespace: string,
workspace: vscode.WorkspaceFolder
workspace: vscode.WorkspaceFolder,
): WorkspaceSettings {
const config = getConfiguration(namespace, workspace);

Expand All @@ -45,15 +45,15 @@ export function getWorkspaceSettings(

function getOptionalUserValue<T>(
config: vscode.WorkspaceConfiguration,
key: string
key: string,
): T | undefined {
const inspect = config.inspect<T>(key);
return inspect?.globalValue;
}

function getConfiguration(
config: string,
scope?: vscode.ConfigurationScope
scope?: vscode.ConfigurationScope,
): vscode.WorkspaceConfiguration {
return vscode.workspace.getConfiguration(config, scope);
}

0 comments on commit ef6f3a6

Please sign in to comment.