-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
29 lines (22 loc) · 929 Bytes
/
utils.ts
File metadata and controls
29 lines (22 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import * as vscode from "vscode";
import * as path from "path";
import * as os from "os";
import { EXTENSION_NAME } from "./constants";
export const createCommandName = (name: string) => `${EXTENSION_NAME}.${name}`;
export function getLineFromOffset(content: string, offset: number): number {
return content.slice(0, offset).split(/\r?\n/).length;
}
export function getNotesDir(context: vscode.ExtensionContext): string {
const config = vscode.workspace.getConfiguration(EXTENSION_NAME);
const customPath = config.get<string>("notesDirectory");
if (customPath && customPath.trim() !== "") {
const expandedPath = customPath.startsWith("~")
? path.join(os.homedir(), customPath.slice(1))
: customPath;
return path.resolve(expandedPath);
}
return getDefaultNotesDir(context);
}
export function getDefaultNotesDir(context: vscode.ExtensionContext) {
return context.globalStorageUri.fsPath;
}