Skip to content

Commit

Permalink
feat: linenoteplus
Browse files Browse the repository at this point in the history
  • Loading branch information
prmichaelsen committed Sep 3, 2023
1 parent 00a7579 commit f91fc9c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 61 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Line Note
# Line Note Plus

Line Note is VSCode extension to add notes to the line of code.
Line Note Plus is a VSCode extension to add Markdown notes to your code
that are visible when hovering over the noted line.

[VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=tkrkt.linenote)
[VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=prmichaelsen.linenoteplus)

## Features

Select lines and invoke `Add note at current position` from the command palette or context menu.
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/linenote` like `.vscode/linenote/path/to/code.js#L13-L42.md`.
Notes are saved in `$PROJECT_ROOT/.vscode/linenoteplus` like `.vscode/linenoteplus/<short-uid>.md`.

![example](https://i.imgur.com/KlQtCsL.gif)

Tips: You can put hyperlinks in notes by writing `#L42` or `../foo.js#L12-L15`.
### Demo
* Adding and removeing notes: https://storage.googleapis.com/com-f5-parm.appspot.com/parm/images/XK7AHFrBrfD7LpliwDX5.quicktime
* Notes move with code: https://storage.googleapis.com/com-f5-parm.appspot.com/parm/images/KbetjziHdRWmfHpJu5FN.quicktime
46 changes: 24 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "linenote",
"displayName": "Line Note",
"name": "linenoteplus",
"displayName": "Line Note Plus",
"description": "Add notes to the line of source code",
"version": "1.2.1",
"publisher": "tkrkt",
"version": "1.2.2",
"publisher": "prmichaelsen",
"engines": {
"vscode": "^1.30.0"
},
Expand All @@ -17,79 +17,81 @@
],
"repository": {
"type": "git",
"url": "https://github.com/tkrkt/linenote.git"
"url": "https://github.com/prmichaelsen/linenoteplus.git"
},
"keywords": [
"vscode",
"note",
"comment",
"notataion",
"annotation",
"line",
"tooltip"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "linenote.addNote",
"command": "linenoteplus.addNote",
"title": "%command.addNote.title%"
},
{
"command": "linenote.openNote",
"command": "linenoteplus.openNote",
"title": "%command.openNote.title%"
},
{
"command": "linenote.revealLine",
"command": "linenoteplus.revealLine",
"title": "%command.revealLine.title%"
},
{
"command": "linenote.removeNote",
"command": "linenoteplus.removeNote",
"title": "%command.removeNote.title%"
}
],
"menus": {
"editor/context": [
{
"command": "linenote.addNote"
"command": "linenoteplus.addNote"
},
{
"command": "linenote.revealLine",
"command": "linenoteplus.revealLine",
"when": "isActiveEditorNote"
}
]
},
"configuration": {
"type": "object",
"title": "Line Note",
"title": "Line Note Plus",
"properties": {
"linenote.lineColor": {
"linenoteplus.lineColor": {
"type": "string",
"default": "rgba(255, 255, 0, 0.05)",
"description": "%configuration.lineColor.description%"
},
"linenote.rulerColor": {
"linenoteplus.rulerColor": {
"type": "string",
"default": "rgba(255, 255, 0, 0.4)",
"description": "%configuration.rulerColor.description%"
},
"linenote.cleanUpOrphanedNotesInterval": {
"linenoteplus.cleanUpOrphanedNotesInterval": {
"type": "integer",
"default": 60000,
"description": "%configuration.cleanUpOrphanedNotesInterval.description%"
},
"linenote.showGutterIcon": {
"linenoteplus.showGutterIcon": {
"type": "boolean",
"default": true,
"description": "%configuration.showGutterIcon.description%"
},
"linenote.gutterIconPath": {
"linenoteplus.gutterIconPath": {
"type": [
"string",
"null"
],
"default": "images/gutter.png",
"description": "%configuration.gutterIconPath.description%"
},
"linenote.cleanUpOrphanedNotes": {
"linenoteplus.cleanUpOrphanedNotes": {
"type": [
"on-save",
"on-interval",
Expand All @@ -99,23 +101,23 @@
"default": "on-save-and-on-interval",
"description": "%configuration.cleanUpOrphanedNotes.description%"
},
"linenote.includePaths": {
"linenoteplus.includePaths": {
"type": "array",
"default": [
"**/src/**/*",
"**/.vscode/linenote/**/*"
"**/.vscode/linenoteplus/**/*"
],
"description": "%configuration.includePaths.description%"
}
}
}
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "yarn run compile && node ./node_modules/vscode/bin/test"
"test": "npm run compile && node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"@types/chokidar": "^1.7.5",
Expand Down
6 changes: 3 additions & 3 deletions package.nls.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"command.addNote.title": "Line Note: Add note at current position",
"command.addNote.title": "Line Note Plus: Add note at current position",
"command.openNote.title": "Line Note: Edit note at current position",
"command.revealLine.title": "Line Note: Reveal line in notated file",
"command.removeNote.title": "Line Note: Remove note at current position",
"command.revealLine.title": "Line Note Plus: Reveal line in notated file",
"command.removeNote.title": "Line Note Plus: Remove note at current position",
"configuration.cleanUpOrphanedNotesInterval.description": "Interval at which to clean up unused notes in the background in ms. Only applies if cleanupOprhanedNotes is set to 'on-interval' or 'on-save-and-on-interval'. Default: 60000 (60s). For performance, a large value is recommended. In order to determine if a note has a corresponding marker, the entire project directory must be scanned.",
"configuration.cleanUpOrphanedNotes.description": "Whether to cleanup orphaned notes on save file, on change file, on an interval, or never. Default: 'on-save'. Warning: On change file will provide more realtime updates but may affect performance and will delete note files instantly if not found in the changed file. Requires reload.",
"configuration.includePaths.description": "File pattern globs to scan for note markers. Unmatched directories will be ignored.",
Expand Down
4 changes: 2 additions & 2 deletions src/DocumentLinkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class NoteLinkProvider implements DocumentLinkProvider {
const editEndPosition = new Position(line.lineNumber, editIndex + editText.length);
const editRange = new Range(editPosition, editEndPosition);
const editUri = Uri.parse(
`command:linenote.openNote?${encodeURIComponent(
`command:linenoteplus.openNote?${encodeURIComponent(
JSON.stringify(uuid)
)}`
);
Expand All @@ -26,7 +26,7 @@ export class NoteLinkProvider implements DocumentLinkProvider {
const removeEndPosition = new Position(line.lineNumber, removeIndex + removeText.length);
const removeRange = new Range(removePosition, removeEndPosition);
const removeUri = Uri.parse(
`command:linenote.removeNote?${encodeURIComponent(
`command:linenoteplus.removeNote?${encodeURIComponent(
JSON.stringify(uuid)
)}`
);
Expand Down
8 changes: 4 additions & 4 deletions src/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ export class Decorator {
const gutterProp: vscode.DecorationRenderOptions = {};

// set line color
const line: string | undefined = config.get("linenote.lineColor");
const line: string | undefined = config.get("linenoteplus.lineColor");
if (line && line.trim().length) {
noteMarkerProp.backgroundColor = line.trim();
}

// set ruler color
const ruler: string | undefined = config.get("linenote.rulerColor");
const ruler: string | undefined = config.get("linenoteplus.rulerColor");
if (ruler && ruler.trim().length) {
noteMarkerProp.overviewRulerLane = vscode.OverviewRulerLane.Right;
noteMarkerProp.overviewRulerColor = ruler.trim();
}

const showGutterIcon: boolean | undefined = config.get(
"linenote.showGutterIcon"
"linenoteplus.showGutterIcon"
);
if (showGutterIcon) {
let iconPath: string | null = config.get<string | null>("linenote.gutterIconPath")!;
let iconPath: string | null = config.get<string | null>("linenoteplus.gutterIconPath")!;
if (iconPath) {
gutterProp.gutterIconPath = iconPath;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/editorUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const onDidSaveTextDocument = async (document: vscode.TextDocument) => {
// decorate call is debounced.
uuidsToDelete.forEach(async uuid => {
if (uuid) {
await vscode.commands.executeCommand('linenote.removeNote', uuid);
await vscode.commands.executeCommand('linenoteplus.removeNote', uuid);
}
});
}
Expand Down
24 changes: 12 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const activate = (context: vscode.ExtensionContext) => {
const exclude: any = conf.get('files.exclude');
const excludeFiles = {
...exclude,
['.vscode/linenout']: true,
['.vscode/linenoteplus']: true,
};
conf.update('files.exclude', excludeFiles);

Expand All @@ -46,7 +46,7 @@ export const activate = (context: vscode.ExtensionContext) => {
}
const interval = vscode.workspace
.getConfiguration()
.get("linenote.cleanUpOrphanedNotesInterval");
.get("linenoteplus.cleanUpOrphanedNotesInterval");
if (typeof interval === "number" && interval >= 0) {
const start = +new Date();
await cleanUpOrphanedNotes();
Expand All @@ -65,7 +65,7 @@ export const activate = (context: vscode.ExtensionContext) => {
// set cleanup orphaned nodes logic
// based on conf
const cleanupOrphanedNodes =
conf.get<CleanUpOrphanedNodesConf>('linenote.cleanUpOrphanedNotes')!;
conf.get<CleanUpOrphanedNodesConf>('linenoteplus.cleanUpOrphanedNotes')!;
switch (cleanupOrphanedNodes) {
case 'on-save':
cleanupOnSave();
Expand Down Expand Up @@ -138,23 +138,23 @@ export const activate = (context: vscode.ExtensionContext) => {
const note = globalActiveNoteMarkers[uuid];
const body = await note.read();
if (!body.trim().length) {
await vscode.commands.executeCommand('linenote.removeNote', uuid);
await vscode.commands.executeCommand('linenoteplus.removeNote', uuid);
}
}),

vscode.workspace.onDidChangeConfiguration(async event => {
if (
event.affectsConfiguration("linenote.lineColor") ||
event.affectsConfiguration("linenote.rulerColor") ||
event.affectsConfiguration("linenote.cleanupOrphanedNotes") ||
event.affectsConfiguration("linenote.cleanupOrphanedNotesInterval")
event.affectsConfiguration("linenoteplus.lineColor") ||
event.affectsConfiguration("linenoteplus.rulerColor") ||
event.affectsConfiguration("linenoteplus.cleanupOrphanedNotes") ||
event.affectsConfiguration("linenoteplus.cleanupOrphanedNotesInterval")
) {
decorator.reload();
decorator.decorate();
}
}),

registerCommand('linenote.addNote', async (_uuid?: string) => {
registerCommand('linenoteplus.addNote', async (_uuid?: string) => {
const editor = getEditor();
const filePath = editor.document.uri.fsPath;
const noteDir = getNotesDir(editor.document.fileName);
Expand Down Expand Up @@ -194,7 +194,7 @@ export const activate = (context: vscode.ExtensionContext) => {
await note.open();
}),

registerCommand('linenote.openNote', async (uuid?: string) => {
registerCommand('linenoteplus.openNote', async (uuid?: string) => {
const editor = getEditor();
const filePath = editor.document.uri.fsPath;
const noteDir = getNotesDir(editor.document.fileName);
Expand Down Expand Up @@ -230,7 +230,7 @@ export const activate = (context: vscode.ExtensionContext) => {
}),

registerCommand(
"linenote.removeNote",
"linenoteplus.removeNote",
async (uuid?: string) => {
const _uuid = uuid || Note.matchUuidOnActiveLine(getEditor());
if (_uuid) {
Expand All @@ -251,7 +251,7 @@ export const activate = (context: vscode.ExtensionContext) => {
}
),

registerCommand("linenote.revealLine", async () => {
registerCommand("linenoteplus.revealLine", async () => {
const editor = getEditor();
const filePath = editor.document.uri.fsPath;
if (!isNotePath(filePath)) {
Expand Down
6 changes: 3 additions & 3 deletions src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Note implements Props {
constructor(props: ConstructorProps) {
this.filePath = props.filePath;
this.uuid = props.uuid,
// e.g. $PROJECT_ROOT/.vscode/linenote/73WakrfVbNJBaAmhQtEeDv.md
// e.g. $PROJECT_ROOT/.vscode/linenoteplus/73WakrfVbNJBaAmhQtEeDv.md
this.notePath = path.join(props.noteDir, this.uuid + '.md');
this.line = props.line;
}
Expand Down Expand Up @@ -130,12 +130,12 @@ export class Note implements Props {

// create footer
const edit = `[Edit](${vscode.Uri.parse(
`command:linenote.openNote?${encodeURIComponent(
`command:linenoteplus.openNote?${encodeURIComponent(
JSON.stringify(this.uuid)
)}`
)})`;
const remove = `[Remove](${vscode.Uri.parse(
`command:linenote.removeNote?${encodeURIComponent(
`command:linenoteplus.removeNote?${encodeURIComponent(
JSON.stringify(this.uuid)
)}`
)})`;
Expand Down
2 changes: 1 addition & 1 deletion src/noteUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const cleanUpOrphanedNotes = async () => {
}
await Promise.all(uuidsToDelete.map(async uuid => {
if (uuid) {
await vscode.commands.executeCommand('linenote.removeNote', uuid);
await vscode.commands.executeCommand('linenoteplus.removeNote', uuid);
}
}));
}
Expand Down
10 changes: 5 additions & 5 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getUuidFromNotePath = (notePath: string) => {
return uuid;
}

export const relNotesDir = '.vscode/linenote';
export const relNotesDir = '.vscode/linenoteplus';
export const getNotesDir = (filePath: string) => {
const workspaceFolders = vscode.workspace.workspaceFolders!;
for (const folder of workspaceFolders) {
Expand Down Expand Up @@ -56,7 +56,7 @@ export const getIncludedFilePaths = async (): Promise<string[]> => {
const fNames: string[] = [];
const includePaths = vscode.workspace
.getConfiguration()
.get<string[]>('linenote.includePaths')!;
.get<string[]>('linenoteplus.includePaths')!;
for (const pattern of includePaths) {
const files = await vscode.workspace.findFiles(pattern, '');
for (const file of files) {
Expand All @@ -66,12 +66,12 @@ export const getIncludedFilePaths = async (): Promise<string[]> => {
return fNames;
};

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

// get [projectRoot, noteRoot(=projectRot/.vscode/linenote)] from file path.
// get [projectRoot, noteRoot(=projectRot/.vscode/linenoteplus)] from file path.
export const getRootFolders = async (
fsPath: string
): Promise<[string, string]> => {
Expand Down

0 comments on commit f91fc9c

Please sign in to comment.