Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'editors/code/src/util.ts')
-rw-r--r--editors/code/src/util.ts33
1 files changed, 31 insertions, 2 deletions
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts
index 93c7bf8d73..410b055100 100644
--- a/editors/code/src/util.ts
+++ b/editors/code/src/util.ts
@@ -14,11 +14,11 @@ export function assert(condition: boolean, explanation: string): asserts conditi
}
export type Env = {
- [name: string]: string;
+ [name: string]: string | undefined;
};
class Log {
- private readonly output = vscode.window.createOutputChannel("Rust Analyzer Client", {
+ private readonly output = vscode.window.createOutputChannel("rust-analyzer Extension", {
log: true,
});
@@ -299,3 +299,32 @@ export async function spawnAsync(
};
}
}
+
+export const isWindows = process.platform === "win32";
+
+export function isWindowsDriveLetter(code: number): boolean {
+ // Copied from https://github.com/microsoft/vscode/blob/02c2dba5f2669b924fd290dff7d2ff3460791996/src/vs/base/common/extpath.ts#L265-L267
+ return (
+ (code >= /* CharCode.A */ 65 && code <= /* CharCode.Z */ 90) ||
+ (code >= /* CharCode.a */ 97 && code <= /* CharCode.z */ 122)
+ );
+}
+export function hasDriveLetter(path: string, isWindowsOS: boolean = isWindows): boolean {
+ // Copied from https://github.com/microsoft/vscode/blob/02c2dba5f2669b924fd290dff7d2ff3460791996/src/vs/base/common/extpath.ts#L324-L330
+ if (isWindowsOS) {
+ return (
+ isWindowsDriveLetter(path.charCodeAt(0)) &&
+ path.charCodeAt(1) === /* CharCode.Colon */ 58
+ );
+ }
+
+ return false;
+}
+export function normalizeDriveLetter(path: string, isWindowsOS: boolean = isWindows): string {
+ // Copied from https://github.com/microsoft/vscode/blob/02c2dba5f2669b924fd290dff7d2ff3460791996/src/vs/base/common/labels.ts#L140-L146
+ if (hasDriveLetter(path, isWindowsOS)) {
+ return path.charAt(0).toUpperCase() + path.slice(1);
+ }
+
+ return path;
+}