Skip to content

Commit

Permalink
feat: configure notesDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
prmichaelsen committed Sep 4, 2023
1 parent cc02f7e commit c1aeac4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ that are visible when hovering over the noted line. Based on [Line Note](https:/
Invoke `Add note at current position` from the command palette or context menu.
You can see the note you wrote as hover text.

Notes are saved in `$PROJECT_ROOT/.vscode/.linenoteplus` like `.vscode/.linenoteplus/<short-uid>.md`.
Notes are saved by default in `$PROJECT_ROOT/.vscode/.linenoteplus` like `.vscode/.linenoteplus/<short-uid>.md`.

### Overview
* Edit/open or remove note via Cmd + Click
Expand All @@ -30,7 +30,7 @@ Notes are saved in `$PROJECT_ROOT/.vscode/.linenoteplus` like `.vscode/.linenote
* Notes can be moved between files
* Notes are not affected by refactors
* Add notes within your notes
* Customize note marker background color and annoted line ruler color
* Customize notes directory, note marker background color, and annoted line ruler color
* Configure to delete orphaned notes `on-save`, `on-inteveral`, `on-save-and-on-interval`, or `never`

### API
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
"default": true,
"description": "%configuration.showGutterIcon.description%",
"type": "boolean"
},
"linenoteplus.notesDirectory": {
"default": ".vscode/.linenoteplus",
"description": "%configuration.notesDirectory.description%",
"type": "string"
}
},
"title": "Line Note Plus",
Expand Down Expand Up @@ -153,5 +158,5 @@
"vscode:prepublish": "npm run compile",
"watch": "tsc -watch -p ./"
},
"version": "2.1.4"
"version": "2.2.0"
}
7 changes: 4 additions & 3 deletions package.nls.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"command.addNote.title": "Line Note Plus: Add note at current position (Annotate Line)",
"command.openNote.title": "Line Note Plus: Edit note at current position (Open Note)",
"command.revealLine.title": "Line Note Plus: Reveal line in notated file (Show Note Marker)",
"command.removeNote.title": "Line Note Plus: Remove note at current position (Delete Note)",
"configuration.cleanUpOrphanedNotesInterval.description": "Interval at which to clean up unused notes in the background in ms. Only applies if `cleanUpOrphanedNotes` is set to `on-interval` or `on-save-and-on-interval`. Default: `60000` (60s). For performance, a larger value is recommended.",
"command.revealLine.title": "Line Note Plus: Reveal line in notated file (Show Note Marker)",
"configuration.cleanUpOrphanedNotes.description": "Defines the cleanup behavior for orphaned notes. It can be set to `on-save`, `on-interval`, `on-save-and-on-interval`, or `never`. Default: `on-save-and-on-internal`. Note that when using `on-save` or `on-save-and-on-interval`, if you delete a note marker and save the file then your note file will also be deleted.",
"configuration.includePaths.description": "Specifies file pattern globs to scan for note markers. Directories that don't match these patterns will be ignored.",
"configuration.cleanUpOrphanedNotesInterval.description": "Interval at which to clean up unused notes in the background in ms. Only applies if `cleanUpOrphanedNotes` is set to `on-interval` or `on-save-and-on-interval`. Default: `60000` (60s). For performance, a larger value is recommended.",
"configuration.gutterIconPath.description": "File path of the icon to be displayed in gutter.",
"configuration.includePaths.description": "Specifies file pattern globs to scan for note markers. Directories that don't match these patterns will be ignored.",
"configuration.lineColor.description": "Sets the background color for inline note markers (Name, HEX, or RGB).",
"configuration.notesDirectory.description": "Directory to store saved notes. Default: `.vscode/.linenoteplus`.",
"configuration.rulerColor.description": "Sets the ruler color for notated lines (Name, HEX, or RGB).",
"configuration.showGutterIcon.description": "Whether to display the gutter icon in the gutter for a noted line. Default: `true`."
}
2 changes: 1 addition & 1 deletion src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from "path";
import * as vscode from "vscode";
import { getEditor } from "./editorUtil";
import { globalActiveNoteMarkers } from "./extension";
import { getNoteMarkerRegex, getUuidFromMatch, relNotesDir } from "./noteUtil";
import { getNoteMarkerRegex, getUuidFromMatch } from "./noteUtil";

export interface Props {
filePath: string;
Expand Down
15 changes: 8 additions & 7 deletions src/noteUtil.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as chokidar from "chokidar";
import * as fs from "fs-extra";
import * as path from "path";
import * as chokidar from "chokidar";
import * as vscode from 'vscode';
import { GlobalActiveNoteMarkers, globalActiveNoteMarkers } from "./extension";
import { Note } from "./note";
import {
escapeRegex,
getIncludedFilePaths,
identityDiffArr,
keys,
escapeRegex,
} from "./util";
import { Note } from "./note";
import * as vscode from 'vscode';
import { GlobalActiveNoteMarkers, globalActiveNoteMarkers } from "./extension";


export const getNotePrefix = () => {
Expand All @@ -28,8 +28,9 @@ export const getUuidFromNotePath = (notePath: string) => {
return uuid;
}

export const relNotesDir = '.vscode/.linenoteplus';
export const getNotesDir = (filePath: string) => {
const conf = vscode.workspace.getConfiguration();
const relNotesDir: any = conf.get('linenoteplus.notesDirectory');
const workspaceFolders = vscode.workspace.workspaceFolders!;
for (const folder of workspaceFolders) {
const folderPath = folder.uri.fsPath
Expand Down Expand Up @@ -169,7 +170,7 @@ export const initializeGlobalActiveNoteMarkers = async (
const workspaceFolders = vscode.workspace.workspaceFolders!;
for (const folder of workspaceFolders) {
const folderPath = folder.uri.fsPath
const noteDir = path.join(folderPath, relNotesDir);
const noteDir = getNotesDir(folderPath);
const filePaths = await getIncludedFilePaths();
for (const filePath of filePaths) {
const document = await vscode.workspace.openTextDocument(filePath);
Expand Down
20 changes: 0 additions & 20 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ export const getIncludedFilePaths = async (): Promise<string[]> => {
return fNames;
};

// convert from $PROJECT_ROOT to $PROJECT_ROOT/.vscode/.linenoteplus
export const fromProjectRootToNoteRoot = (projectRoot: string): string => {
return path.join(projectRoot, ".vscode", "linenoteplus");
};

// get [projectRoot, noteRoot(=projectRot/.vscode/.linenoteplus)] from file path.
export const getRootFolders = async (
fsPath: string
): Promise<[string, string]> => {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(
vscode.Uri.file(fsPath)
);
if (workspaceFolder) {
const projectRoot = workspaceFolder.uri.fsPath;
return [projectRoot, fromProjectRootToNoteRoot(projectRoot)];
} else {
throw new Error("workspace not found");
}
};

// convert from Promise<T>[] to Promise<T[]> by filtering resolved promises
export const filterResolved = async <T>(
promises: Promise<T>[]
Expand Down

0 comments on commit c1aeac4

Please sign in to comment.