Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 153 additions & 57 deletions package.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions scripts/keymap.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const PREFIXES = [{ key: 'ctrl+[IntlBackslash]', arg: '<' }, { key: "ctrl
/** Bindings outside the chord scheme. */
export const OTHERS = [
{ command: 'codeNotes.cancelMove', key: 'escape', when: 'codeNotes.moving && editorTextFocus && !suggestWidgetVisible && !findWidgetVisible' },
// Moving a note: Enter puts it on the selected lines (the status bar item says so).
{ command: 'codeNotes.moveToSelection', key: 'enter', when: 'codeNotes.moving && editorTextFocus && !suggestWidgetVisible' },
// Esc in an empty new note box closes it and keeps the draft.
{ command: 'codeNotes.closeNoteBox', key: 'escape', when: 'commentEditorFocused && commentController == codeNotes && commentThreadIsEmpty' },
]

/**
Expand Down
11 changes: 4 additions & 7 deletions src/notes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export type { NotesFeaturePorts } from './ports'
/** A file in the notes folder (the store watches it: no note or step is on it). */
export { inNotesFolder } from './notesFolder'

/** Closes a new note box, keeping its draft (create.ts closeNoteBox). */
export const CLOSE_NOTE_BOX = 'codeNotes.closeNoteBox'

/** The id VS Code knows the notes' comment threads by. */
const CONTROLLER_ID = 'codeNotes'

Expand Down Expand Up @@ -96,23 +93,23 @@ export async function activateNotes(context: vscode.ExtensionContext, ports: Not
// A note you made is read (its first message is yours): stored in the background (a round trip to the window).
onDidCreateNote((n) => fireAndForget(setSeen([[n.data.id, 1]]), 'seen')),
takeLinks((link) => stepLink(ports.layout, link)),
// Esc in a new note box (the key is the manifest's); not in the command table yet, so registered here.
vscode.commands.registerCommand(CLOSE_NOTE_BOX, async () => {
// Esc in a new note box (the key is the manifest's): closes it, keeping its draft (create.ts closeNoteBox).
vscode.commands.registerCommand(HiddenCmd.closeNoteBox, async () => {
try { await closeNoteBox() } finally { drafting.fire(false) }
}),
)
registerCommands(context, {
// Adding, replying, asking from a thread. A note being written pauses what plays (its code stays put under it).
[Cmd.add]: chord(() => { drafting.fire(true); return addNote() }),
[Cmd.addQuick]: addQuickNote,
[HiddenCmd.addQuick]: addQuickNote,
[Cmd.addPathNote]: (uri?: vscode.Uri, text?: unknown) => addPathNote(uri, text),
[Cmd.askFromThread]: askFromThread,
[Cmd.createFromThread]: async (...a: Parameters<typeof createFromThread>) => {
try { return await createFromThread(...a) } finally { drafting.fire(false) }
},
[Cmd.reply]: replyTo,
[Cmd.replyReopen]: replyTo, // the same, labelled for resolved threads
[Cmd.replyResolve]: replyAndResolve,
[HiddenCmd.replyResolve]: replyAndResolve,
[Cmd.applySuggestion]: (id: string, mi: number, k: number) => applySuggestion(id, mi, k),
// Resolving, deleting, moving, reading.
[Cmd.resolve]: async (arg?: CommandArg, many?: readonly CommandArg[]) => resolve(await pickNotes(arg, many)),
Expand Down
24 changes: 14 additions & 10 deletions src/platform/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
/** The contributed commands (package.json), by name; the comment is the title the palette shows. */
export const Cmd = {
add: 'codeNotes.add', // Add Note
addQuick: 'codeNotes.addQuick', // Add One-Line Note
reply: 'codeNotes.reply', // Reply
createFromThread: 'codeNotes.createFromThread', // Add Note
createFromThread: 'codeNotes.createFromThread', // Save Note
reveal: 'codeNotes.reveal', // Open Thread
resolve: 'codeNotes.resolve', // Resolve
reopen: 'codeNotes.reopen', // Reopen
Expand All @@ -31,10 +30,9 @@ export const Cmd = {
find: 'codeNotes.find', // Find Note…
refresh: 'codeNotes.refresh', // Reload Notes
copyAgentPrompt: 'codeNotes.copyAgentPrompt', // Copy Prompt for Agent
replyResolve: 'codeNotes.replyResolve', // Reply & Resolve
hideSession: 'codeNotes.hideSession', // Hide Session in Editor
showSession: 'codeNotes.showSession', // Show Session in Editor
showOnlySession: 'codeNotes.showOnlySession', // Show Only This Session
showOnlySession: 'codeNotes.showOnlySession', // Show Only This Session in Editor
showAllSessions: 'codeNotes.showAllSessions', // Show All Sessions
resolveSession: 'codeNotes.resolveSession', // Resolve Session…
deleteSession: 'codeNotes.deleteSession', // Delete Session…
Expand All @@ -50,7 +48,7 @@ export const Cmd = {
restoreBroken: 'codeNotes.restoreBroken', // Restore Last Good Version
collapseThread: 'codeNotes.collapseThread', // Show Fewer Replies
openJourney: 'codeNotes.openJourney', // Open Journey…
askQuestion: 'codeNotes.askQuestion', // Ask a Question About the Code…
askQuestion: 'codeNotes.askQuestion', // Find or Write a Journey…
startJourney: 'codeNotes.startJourney', // Start Journey
nextStep: 'codeNotes.nextStep', // Next Step
previousStep: 'codeNotes.previousStep', // Previous Step
Expand Down Expand Up @@ -81,6 +79,11 @@ export const Cmd = {
answerCheck: 'codeNotes.answerCheck', // Answer
gradeCheck: 'codeNotes.gradeCheck', // Grade the Answer Again
checkConcern: 'codeNotes.checkConcern', // Act on a Concern Found During the Check
// A check concern's actions, buttons on its thread.
concernFix: 'codeNotes.concernFix', // Suggest a Fix
concernTodo: 'codeNotes.concernTodo', // Add TODO
concernFlag: 'codeNotes.concernFlag', // Flag for Reviewer
concernDismiss: 'codeNotes.concernDismiss', // Dismiss Concern
pickJourneyStep: 'codeNotes.pickJourneyStep', // Pick a Journey Step Here
searchJourneys: 'codeNotes.searchJourneys', // Search Journeys
sortJourneys: 'codeNotes.sortJourneys', // Sort Journeys
Expand All @@ -103,12 +106,13 @@ export const HiddenCmd = {
podcastFollow: 'codeNotes.podcastFollow',
/** A thread's links run through this one with a short key (shortLinks below). */
link: 'codeNotes.link',
/** A check concern's actions on its thread (menus on the thread, not links in the text). */
concernFix: 'codeNotes.concernFix',
concernTodo: 'codeNotes.concernTodo',
concernFlag: 'codeNotes.concernFlag',
/** A concern marked fixed (the commit that fixes it does this; no button). */
concernFixed: 'codeNotes.concernFixed',
concernDismiss: 'codeNotes.concernDismiss',
/** Not contributed (no menu or key runs them); still registered for keybindings people wrote themselves. */
addQuick: 'codeNotes.addQuick',
replyResolve: 'codeNotes.replyResolve',
/** Esc in a new note box (the manifest's key). */
closeNoteBox: 'codeNotes.closeNoteBox',
notesFocus: 'codeNotes.notes.focus',
journeysFocus: 'codeNotes.journeys.focus',
checkFocus: 'codeNotes.check.focus',
Expand Down
8 changes: 4 additions & 4 deletions src/threads/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export function activateThreads(context: vscode.ExtensionContext, ports: Threads
const call = linkCall(key)
return call ? vscode.commands.executeCommand(call.command, ...call.args) : undefined
},
[HiddenCmd.concernFix]: concern('fix'),
[HiddenCmd.concernTodo]: concern('todo'),
[HiddenCmd.concernFlag]: concern('flag'),
[Cmd.concernFix]: concern('fix'),
[Cmd.concernTodo]: concern('todo'),
[Cmd.concernFlag]: concern('flag'),
[HiddenCmd.concernFixed]: concern('fixed'),
[HiddenCmd.concernDismiss]: concern('dismiss'),
[Cmd.concernDismiss]: concern('dismiss'),
})
return {
has: (id) => view.has(id),
Expand Down
4 changes: 2 additions & 2 deletions test/integration/main/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { appendMessage, now, quiet, readJson, test } from '../helpers'
import { agentNote, writeLines, writeNote } from '../fixtures'
import { cdp, ui } from '../devtools'
import { BARS, marksOf } from '../../../src/notes/decorations'
import { HiddenCmd } from '../../../src/platform/commands'
import { Cmd, HiddenCmd } from '../../../src/platform/commands'
import { commandLinksIn, ctx, noteById, notePath, snap, until, wsPath } from './context'

/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down Expand Up @@ -70,7 +70,7 @@ export const threadsTests = [
await until('tool.json open at line 3', () => vscode.window.activeTextEditor?.document.uri.fsPath === wsPath('tool.json')
&& vscode.window.activeTextEditor.selection.active.line === 2)
const all = await vscode.commands.getCommands(true)
for (const c of [HiddenCmd.link, HiddenCmd.concernFix, HiddenCmd.concernTodo, HiddenCmd.concernFlag, HiddenCmd.concernFixed, HiddenCmd.concernDismiss]) {
for (const c of [HiddenCmd.link, Cmd.concernFix, Cmd.concernTodo, Cmd.concernFlag, HiddenCmd.concernFixed, Cmd.concernDismiss]) {
assert.ok(all.includes(c), `${c} is registered (the concern's actions on its thread)`)
}
}),
Expand Down
18 changes: 15 additions & 3 deletions test/keybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,23 @@ test('one chord scheme on two prefixes: Ctrl+< by scan code (ISO key) and Ctrl+\
}
}
}
assert.equal(keys.length, PREFIXES.length * Object.keys(CHORDS).length * 2 + 1 /* escape */, 'nothing else but escape')
assert.equal(keys.length, PREFIXES.length * Object.keys(CHORDS).length * 2 + 3, 'nothing else but Esc and Enter (below)')
// VS Code shows the last binding of a command: the plain chord, "Ctrl+' D".
for (const command of Object.values(CHORDS)) assert.equal(keys.filter((k) => k.command === command).pop()!.key.replace(/^\S+ /, ''), Object.keys(CHORDS).find((k) => CHORDS[k] === command))
assert.ok(keys.some((k) => k.key === 'escape' && k.command === 'codeNotes.cancelMove'))
})

test('outside the chords: Esc and Enter only where they belong to Code Notes', () => {
const others = keys.filter((k) => !k.args)
assert.deepEqual(others, [
{ command: 'codeNotes.cancelMove', key: 'escape', when: 'codeNotes.moving && editorTextFocus && !suggestWidgetVisible && !findWidgetVisible' },
// Moving a note: Enter puts it on the selection (the status bar item's action).
{ command: 'codeNotes.moveToSelection', key: 'enter', when: 'codeNotes.moving && editorTextFocus && !suggestWidgetVisible' },
// Esc in an empty new note box of ours closes it (the draft is kept); other comment boxes keep their Esc.
{ command: 'codeNotes.closeNoteBox', key: 'escape', when: 'commentEditorFocused && commentController == codeNotes && commentThreadIsEmpty' },
])
})

test('the chord table is the scheme as documented: letters for notes and journeys, arrows and space for listening', async () => {
assert.deepEqual((await keymap()).CHORDS, {
c: 'codeNotes.add',
Expand All @@ -63,7 +74,8 @@ test('the chord table is the scheme as documented: letters for notes and journey
})
})

test('every bound command is contributed', () => {
test('every bound command is contributed, except closing the note box (a key, not a verb for the palette)', () => {
const cmds = new Set(pkg.contributes.commands.map((c: { command: string }) => c.command))
for (const k of keys) assert.ok(cmds.has(k.command), k.command)
for (const k of keys.filter((x) => x.command !== 'codeNotes.closeNoteBox')) assert.ok(cmds.has(k.command), k.command)
assert.ok(!cmds.has('codeNotes.closeNoteBox'))
})
Loading
Loading