Skip to content

Commit

Permalink
release v1.1.0 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-z authored Apr 7, 2022
1 parent dbe7bf5 commit eb87f74
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
"--extensionTestsPath=${workspaceFolder}/out/tests/suite/index"
],
"outFiles": ["${workspaceFolder}/out/**/*.js", "${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "tasks: watch-tests"
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ You are then able to jump to `editor 1` or `editor 2` from anywhere in your work
[1-9]
- `VSCode Harpoon: Edit Editors (vscode-harpoon.editEditors)` Opens an editor for you do delete or
move added editors around.
- `VSCode Harpoon: Editor Quick Pick (vscode-harpoon.editorQuickPick)` Opens a quick pick menu to
pick between your current workspace editors
- `VSCode Harpoon: Add Global Editor (vscode-harpoon.addGlobalEditor)` adds the current editor
globally
- `VSCode Harpoon: Go to global editor [1-9] (vscode-harpoon.gotoGlobalEditor[1-9])` Goes to global
editor [1-9]
- `VSCode Harpoon: Edit Global Editors (vscode-harpoon.editGlobalEditors)` Opens an editor for you
do delete or move added editors around.
- `VSCode Harpoon: Editor Global Quick Pick (vscode-harpoon.editorGlobalQuickPick)` Opens a quick
pick menu to pick between your global editors

## Example Keybinds

Expand All @@ -49,6 +53,10 @@ You are then able to jump to `editor 1` or `editor 2` from anywhere in your work
"key": "alt+e",
"commands": ["vscode-harpoon.editEditors"]
},
{
"key": "alt+p",
"commands": ["vscode-harpoon.editorQuickPick"]
},
{
"key": "alt+1",
"command": "vscode-harpoon.gotoEditor1"
Expand All @@ -70,6 +78,10 @@ You are then able to jump to `editor 1` or `editor 2` from anywhere in your work
"before": ["<leader>", "e"],
"commands": ["vscode-harpoon.editEditors"]
},
{
"before": ["<leader>", "p", "e"],
"commands": ["vscode-harpoon.editorQuickPick"]
},
{
"before": ["<leader>", "1"],
"commands": ["vscode-harpoon.gotoEditor1"]
Expand Down
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "vscode-harpoon",
"displayName": "VSCode Harpoon",
"description": "A vscode clone of the vim plugin Harpoon created by The Primeagen",
"version": "1.0.2",
"version": "1.1.0",
"license": "MIT",
"homepage": "https://github.com/tobias-z/vscode-harpoon/blob/main/README.md",
"repository": {
Expand Down Expand Up @@ -35,6 +35,7 @@
"onCommand:vscode-harpoon.gotoEditor7",
"onCommand:vscode-harpoon.gotoEditor8",
"onCommand:vscode-harpoon.gotoEditor9",
"onCommand:vscode-harpoon.editorQuickPick",
"onCommand:vscode-harpoon.addGlobalEditor",
"onCommand:vscode-harpoon.editGlobalEditors",
"onCommand:vscode-harpoon.gotoGlobalEditor1",
Expand All @@ -45,7 +46,8 @@
"onCommand:vscode-harpoon.gotoGlobalEditor6",
"onCommand:vscode-harpoon.gotoGlobalEditor7",
"onCommand:vscode-harpoon.gotoGlobalEditor8",
"onCommand:vscode-harpoon.gotoGlobalEditor9"
"onCommand:vscode-harpoon.gotoGlobalEditor9",
"onCommand:vscode-harpoon.editorGlobalQuickPick"
],
"main": "./dist/harpoon.js",
"contributes": {
Expand Down Expand Up @@ -94,6 +96,10 @@
"command": "vscode-harpoon.gotoEditor9",
"title": "VSCode Harpoon: Go to editor 9"
},
{
"command": "vscode-harpoon.editorQuickPick",
"title": "VSCode Harpoon: Editor Quick Pick"
},
{
"command": "vscode-harpoon.addGlobalEditor",
"title": "VSCode Harpoon: Add Global Editor"
Expand Down Expand Up @@ -137,6 +143,10 @@
{
"command": "vscode-harpoon.gotoGlobalEditor9",
"title": "VSCode Harpoon: Go to global editor 9"
},
{
"command": "vscode-harpoon.editorGlobalQuickPick",
"title": "VSCode Harpoon: Editor Global Quick Pick"
}
]
},
Expand All @@ -149,7 +159,7 @@
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "yarn compile-tests && yarn compile && yarn lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js",
"test": "node ./out/tests/runTest.js",
"setup": "yarn && yarn pretest && yarn test",
"update-version": "node scripts/version.cjs",
"deploy": "vsce publish --yarn"
Expand Down
16 changes: 13 additions & 3 deletions scripts/version.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ const { getArgs, handleProcess } = require("./utils.cjs");

async function version() {
const args = getArgs();
if (!args.includes("--major")) {
const isMinor = args.includes("--minor");
if (!args.includes("--major") && !isMinor) {
executeCommand("npm version patch");
return;
}

const packageJson = await getPackageJson();
const newMajor = parseFloat(packageJson.version) + 1;
packageJson.version = `${newMajor}.0.0`;
packageJson.version = getNewVersion(packageJson.version, isMinor);
await fs.writeFile(getPath(), JSON.stringify(packageJson));
executeCommand(`git tag v${packageJson.version}`);
}

function getNewVersion(currentVersion, isMinor) {
if (isMinor) {
const oldMinor = currentVersion.split(".")[1];
return `${parseFloat(currentVersion)}.${parseInt(oldMinor) + 1}.0`;
}
const newMajor = parseFloat(currentVersion) + 1;
return `${newMajor}.0.0`;
}

async function getPackageJson() {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/command-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type CommandName =
| "gotoEditor7"
| "gotoEditor8"
| "gotoEditor9"
| "editorQuickPick"
| "addGlobalEditor"
| "editGlobalEditors"
| "gotoGlobalEditor1"
Expand All @@ -22,7 +23,8 @@ type CommandName =
| "gotoGlobalEditor6"
| "gotoGlobalEditor7"
| "gotoGlobalEditor8"
| "gotoGlobalEditor9";
| "gotoGlobalEditor9"
| "editorGlobalQuickPick";

export default class CommandFactory {
constructor(private readonly context: vscode.ExtensionContext) {}
Expand Down
1 change: 1 addition & 0 deletions src/commands/edit-editors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function prepareEditFile(workspace: readonly vscode.WorkspaceFolder[]) {

function isEditor(editor: string) {
if (!isWindows()) {
editor.startsWith(getSlash());
return editor.startsWith(getSlash());
}
return editor.startsWith("c:") || editor.startsWith("C:");
Expand Down
27 changes: 27 additions & 0 deletions src/commands/editor-quick-pick.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as vscode from "vscode";
import ActiveProjectService, { Editor } from "../service/active-project-service";
import WorkspaceService from "../service/workspace-service";

export default function createEditorQuickPickCommand(
activeProjectService: ActiveProjectService,
workspaceService: WorkspaceService
) {
return async () => {
const items = activeProjectService.activeEditors.map(toQuickPickItem);
const pickedEditor = await vscode.window.showQuickPick(items);
if (!pickedEditor) {
return;
}

workspaceService.changeEditorByName(pickedEditor.description!);
};
}

function toQuickPickItem(editor: Editor) {
const label = editor.fileName.substring(editor.fileName.lastIndexOf("/") + 1);

return {
label,
description: editor.fileName,
};
}
2 changes: 1 addition & 1 deletion src/commands/goto-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import WorkspaceService from "../service/workspace-service";
export function createGotoEditorCommand(workspaceService: WorkspaceService) {
return (id: number) => {
return async () => {
await workspaceService.changeEditor(id);
await workspaceService.changeEditorById(id);
};
};
}
5 changes: 5 additions & 0 deletions src/harpoon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CommandFactory from "./commands/command-factory";
import { createGotoEditorCommand } from "./commands/goto-editor";
import createAddEditorCommand from "./commands/add-editor";
import createEditEditorsCommand from "./commands/edit-editors";
import createEditorQuickPickCommand from "./commands/editor-quick-pick";

export type State = "workspaceState" | "globalState";

Expand Down Expand Up @@ -50,4 +51,8 @@ function registerCommands(
commandFactory.registerCommand(`goto${key}Editor7`, gotoEditor(7));
commandFactory.registerCommand(`goto${key}Editor8`, gotoEditor(8));
commandFactory.registerCommand(`goto${key}Editor9`, gotoEditor(9));
commandFactory.registerCommand(
`editor${key}QuickPick`,
createEditorQuickPickCommand(activeProjectService, workspaceService)
);
}
2 changes: 1 addition & 1 deletion src/service/active-project-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Editor = {
export type Editor = {
fileName: string;
};

Expand Down
23 changes: 17 additions & 6 deletions src/service/workspace-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import ActiveProjectService from "./active-project-service";
import ActiveProjectService, { Editor } from "./active-project-service";
import { getStateKey, State } from "../harpoon";

export default class WorkspaceService {
Expand All @@ -13,16 +13,27 @@ export default class WorkspaceService {
this.stateKey = getStateKey(state);
}

public async changeEditor(id: number) {
public async changeEditorById(id: number) {
const editor = this.activeProjectService.getEditor(id);
return await this.changeFile(editor);
}

public async changeEditorByName(editorName: string) {
const editor = this.activeProjectService.activeEditors.find(
editor => editor.fileName === editorName
);
return await this.changeFile(editor);
}

public saveWorkspace() {
this.context[this.state].update(this.stateKey, this.activeProjectService.activeEditors);
}

private async changeFile(editor?: Editor) {
if (!editor) {
return;
}
const doc = await vscode.workspace.openTextDocument(editor.fileName.trim());
return await vscode.window.showTextDocument(doc);
}

public saveWorkspace() {
this.context[this.state].update(this.stateKey, this.activeProjectService.activeEditors);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ suite("workspace service", () => {
test("can change editor", async () => {
const expected = `${process.cwd()}${getSlash()}package.json`;
activeProjectService.addEditor({ fileName: expected });
const doc = await workspaceService.changeEditor(1);
const doc = await workspaceService.changeEditorById(1);
assert.strictEqual(doc?.document.fileName, expected);
});

Expand All @@ -30,14 +30,21 @@ suite("workspace service", () => {
const gitIgnore = `${process.cwd()}${getSlash()}.gitignore`;

activeProjectService.addEditor({ fileName: packageJson });
const firstDoc = await workspaceService.changeEditor(1);
const firstDoc = await workspaceService.changeEditorById(1);
const firstWorkspace = firstDoc?.document.fileName;

activeProjectService.addEditor({ fileName: gitIgnore });
const secondDoc = await workspaceService.changeEditor(2);
const secondDoc = await workspaceService.changeEditorById(2);
const secondWorkspace = secondDoc?.document.fileName;

assert.strictEqual(secondWorkspace, gitIgnore);
assert.notStrictEqual(firstWorkspace, secondWorkspace);
});

test("can change editor with fileName", async () => {
const expected = `${process.cwd()}${getSlash()}package.json`;
activeProjectService.addEditor({ fileName: expected });
const doc = await workspaceService.changeEditorByName(expected);
assert.strictEqual(doc?.document.fileName, expected);
});
});

0 comments on commit eb87f74

Please sign in to comment.