Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to get hat decorations #4

Open
wants to merge 71 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
3e03dc6
CommandRunner, addDecorationsToEditor, build: restage changes for the…
phillco May 14, 2022
4ff1bbf
cursorless: update iml
phillco May 23, 2022
7620a74
Merge remote-tracking branch 'upstream/main'
phillco May 23, 2022
5e3f19f
iml: fixed trailing \n
phillco Jun 7, 2022
f017056
Merge remote-tracking branch 'upstream/main'
phillco Jun 7, 2022
c420c8d
package, third-party-licenses: bump
phillco Jun 18, 2022
85e89fb
Merge remote-tracking branch 'upstream/main'
phillco Jun 18, 2022
de1a4d5
package: fix installation (you can't have a dash in the author name)
phillco Jun 18, 2022
bbca2bc
build: remove unnecessary steps
phillco Jun 18, 2022
e3b3ecd
addDecorationsToEditor: move hat file location to ~/.cursorless/vscod…
phillco Jun 18, 2022
f3af1ae
package: unique ID
phillco Jun 19, 2022
62a9c1d
bump version
phillco Jun 19, 2022
6ccaba7
Merge remote-tracking branch 'upstream/main'
phillco Jun 25, 2022
6bd462d
package: bump version after merge
phillco Jun 25, 2022
d4730ba
Merge remote-tracking branch 'upstream/main'
phillco Jul 2, 2022
c91c311
package: bump after merge
phillco Jul 2, 2022
3187afc
build: same changes from sidecar; use the command socket to reload th…
phillco Jul 2, 2022
4df431e
Merge remote-tracking branch 'upstream/main'
phillco Jul 7, 2022
6b2d7f5
yarn: merge
phillco Jul 7, 2022
124a490
Merge remote-tracking branch 'upstream/main'
phillco Jul 9, 2022
872ce07
package: bump the version
phillco Jul 9, 2022
a210b34
extension: remove startup message
phillco Jul 10, 2022
a41aea2
Merge remote-tracking branch 'upstream/main'
phillco Jul 17, 2022
ffee7e9
addDecorationsToEditor: include offsets in hat JSON
phillco Jul 19, 2022
caf1b0f
CommandRunner: add a comment
phillco Jul 19, 2022
6eb5322
package: bump version
phillco Jul 19, 2022
3d38e11
Merge remote-tracking branch 'upstream/main'
phillco Jul 23, 2022
3d27065
package: bump version
phillco Jul 23, 2022
79755b9
addDecorationsToEditor: fix the build
phillco Jul 23, 2022
5d2b747
CommandRunner: remove a save after commands (no longer needed)
phillco Jul 23, 2022
4536f80
package: bump version
phillco Jul 23, 2022
2500a7d
FollowLink: just add comment for future reference
phillco Aug 3, 2022
6f59a73
Merge remote-tracking branch 'upstream/main'
phillco Aug 3, 2022
44db5b9
cursorless: exclude dist
phillco Aug 3, 2022
a985a97
cursorless: exclude the sandbox
phillco Aug 3, 2022
5d970b4
Merge remote-tracking branch 'upstream/main'
phillco Aug 6, 2022
9c86595
Merge remote-tracking branch 'upstream/main'
phillco Aug 18, 2022
3c7080e
Merge remote-tracking branch 'upstream/main'
phillco Aug 28, 2022
8d67024
package: bump version
phillco Aug 28, 2022
1f39e25
Merge remote-tracking branch 'upstream/main'
phillco Aug 31, 2022
d8d8ad3
Avoid writing partial hats file to vscode-hats.json (#1)
dyamito Aug 31, 2022
baf5453
Merge remote-tracking branch 'upstream/main'
phillco Sep 5, 2022
09f4948
Merge remote-tracking branch 'upstream/main'
phillco Sep 10, 2022
53cc106
Merge remote-tracking branch 'upstream/main'
phillco Sep 12, 2022
dd70ac7
Merge remote-tracking branch 'upstream/main'
phillco Sep 15, 2022
470b832
addDecorationsToEditor, toPlainObject: refactor rangeToPlainObjectWit…
phillco Sep 17, 2022
637daba
package: bump version
phillco Sep 17, 2022
eb12847
iml: add newline
phillco Sep 17, 2022
156b229
addDecorationsToEditor, getDisplayLineMap: use the superior editor's …
phillco Sep 17, 2022
72e7fee
Merge remote-tracking branch 'upstream/main'
phillco Sep 17, 2022
5b0452a
package: bump version
phillco Sep 17, 2022
02d353a
Merge remote-tracking branch 'upstream/main'
phillco Sep 24, 2022
98e07c6
HatAllocator: trigger addDecorationsDebounced() on editor state chang…
phillco Sep 24, 2022
f1f6ada
package: bump version
phillco Sep 24, 2022
a079b06
package: restore publisher
phillco Sep 24, 2022
48e0558
Fix tests (#2)
dyamito Sep 24, 2022
a017e1b
add command to get cursors
JohnEfford Sep 29, 2022
e3c5eee
build: don't bump the minor version on each build to force Code to pi…
phillco Sep 30, 2022
009bf1a
Merge remote-tracking branch 'upstream/main'
phillco Sep 30, 2022
132ee77
HatAllocator, addDecorationsToEditor: rerun pre-commit
phillco Sep 30, 2022
00e996f
wip for updating visible range
JohnEfford Sep 30, 2022
8a4d701
Merge branch 'main' into feature/add-retrieve-cursor-command
JohnEfford Sep 30, 2022
3dbebd0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 30, 2022
525f8d7
New commands working
JohnEfford Oct 1, 2022
e907b08
Merge branch 'feature/add-retrieve-cursor-command' of https://github.…
JohnEfford Oct 1, 2022
b74fe0f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2022
e4ec43a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2022
7fa4455
Only output hats for current editor
JohnEfford Oct 2, 2022
d2fd4f9
http hats for all editors
JohnEfford Oct 3, 2022
09400d2
Merge branch 'feature/add-retrieve-cursor-command' of https://github.…
JohnEfford Oct 3, 2022
b2fc235
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 3, 2022
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
37 changes: 37 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

set -e

# Remove any previously compiled versions.
rm *.vsix || true

echo "================================================================================"
echo "Packaging extension..."
echo "================================================================================"
yes | vsce package

# Install the compiled extension.
echo ""
echo "================================================================================"
echo "Installing extension..."
echo "================================================================================"

# Uninstalling the old version seems to be necessary to force Code to pick up the new version reliably.
code --uninstall-extension pokey-phillco.cursorless-fork
code --install-extension *.vsix

echo ""
echo "================================================================================"
echo "Reloading VS Code..."
echo "================================================================================"

# Use the command socket to tell VS Code to reload in the background, if socat is installed.
if [[ $(type -P "socat") ]] && [[ -e ~/.cursorless/vscode-socket ]]; then
echo "Reloading VS Code using the command socket..."
echo '{ "command": "command", "commandId": "workbench.action.reloadWindow" }' | socat - ~/.cursorless/vscode-socket
else
echo "Not automatically reloading VS Code because \`socat\` is not installed"
echo "Reload the VS Code window manually (\"window reload\") to get the new version"
fi

echo "Done"
19 changes: 19 additions & 0 deletions cursorless.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Python" name="Python">
<configuration sdkName="Python 2.7 (venv)" />
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/data/playground" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/.vscode-sandbox" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Python 2.7 (venv) interpreter library" level="application" />
</component>
</module>
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cursorless",
"displayName": "Cursorless",
"description": "Structural voice coding at the speed of thought",
"name": "cursorless-fork",
"displayName": "Cursorless (Sidecar Fork)",
"description": "Forked version of Cursorless to be used as a sidecar for other editors.",
"icon": "images/icon.png",
"galleryBanner": {
"color": "#00001A",
Expand All @@ -19,12 +19,12 @@
"description": "Tests"
}
],
"version": "0.26.0",
"publisher": "pokey",
"version": "0.50.66",
"publisher": "pokey-phillco",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/cursorless-dev/cursorless.git"
"url": "https://github.com/phillco/cursorless.git"
},
"homepage": "https://www.cursorless.org/",
"engines": {
Expand Down
6 changes: 6 additions & 0 deletions src/actions/FollowLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export default class FollowLink implements Action {
this.graph.editStyles.referenced
);

// NOTE(pcohen): this is where we would call out to JetBrains
// all "editor actions" need to operate purely on ranges,
// not targets.

// NOTE(pcohen): this is for stuff like links in the
// https://microsoft.com
const link = await getLinkForTarget(target);
if (link) {
await this.openUri(link.target!);
Expand Down
41 changes: 38 additions & 3 deletions src/core/HatAllocator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import * as vscode from "vscode";
import { Disposable } from "vscode";
import { Graph } from "../typings/Types";
import { addDecorationsToEditors } from "../util/addDecorationsToEditor";
import {
addDecorationsToEditors,
getEverywhereInformation,
} from "../util/addDecorationsToEditor";
import { IndividualHatMap } from "./IndividualHatMap";
import { Range } from "vscode";

interface Context {
getActiveMap(): Promise<IndividualHatMap>;
Expand All @@ -13,17 +17,19 @@ export class HatAllocator {
private isActive: boolean;
private disposables: Disposable[] = [];
private disposalFunctions: (() => void)[] = [];
private visibleRange: Range[];

constructor(private graph: Graph, private context: Context) {
graph.extensionContext.subscriptions.push(this);

this.visibleRange = [];
this.isActive = vscode.workspace
.getConfiguration("cursorless")
.get<boolean>("showOnStart")!;

this.addDecorationsDebounced = this.addDecorationsDebounced.bind(this);
this.toggleDecorations = this.toggleDecorations.bind(this);
this.clearEditorDecorations = this.clearEditorDecorations.bind(this);
this.setVisibleRange = this.setVisibleRange.bind(this);

this.disposalFunctions.push(
graph.decorations.registerDecorationChangeListener(
Expand All @@ -36,6 +42,14 @@ export class HatAllocator {
"cursorless.toggleDecorations",
this.toggleDecorations
),
vscode.commands.registerCommand(
"cursorless.getDecorations",
getEverywhereInformation
),
vscode.commands.registerCommand(
"cursorless.setVisibleRange",
this.setVisibleRange
),

// An event that fires when a text document opens
vscode.workspace.onDidOpenTextDocument(this.addDecorationsDebounced),
Expand All @@ -61,6 +75,21 @@ export class HatAllocator {
this.addDecorationsDebounced
)
);

// NOTE(pcohen): this is just a hack until we have extension points between
// the sidecar and Cursorless.
// Update decorations on editor state change since we won't be scrolling the sidecar.
const watcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(
// eslint-disable-next-line @typescript-eslint/no-var-requires
require("os").homedir() + "/.cursorless/",
"*-state.json"
)
);

watcher.onDidChange((_) => {
this.addDecorationsDebounced();
});
}

private clearEditorDecorations(editor: vscode.TextEditor) {
Expand All @@ -76,7 +105,8 @@ export class HatAllocator {
addDecorationsToEditors(
activeMap,
this.graph.decorations,
this.graph.tokenGraphemeSplitter
this.graph.tokenGraphemeSplitter,
this.visibleRange
);
} else {
vscode.window.visibleTextEditors.forEach(this.clearEditorDecorations);
Expand Down Expand Up @@ -104,6 +134,11 @@ export class HatAllocator {
this.addDecorationsDebounced();
}

private setVisibleRange(visible: any) {
const range = [new Range(visible.firstVisible, 0, visible.lastVisible, 0)];
this.visibleRange = range;
}

dispose() {
this.disposables.forEach(({ dispose }) => dispose());
this.disposalFunctions.forEach((dispose) => dispose());
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import CommandRunner from "./core/commandRunner/CommandRunner";
* - Creates an entrypoint for running commands {@link CommandRunner}.
*/
export async function activate(context: vscode.ExtensionContext) {
// NOTE(pcohen): can be used to debug code reloading issues
// vscode.window.showInformationMessage("cursorless-everywhere fork started (v10)!");

const { getNodeAtLocation } = await getParseTreeApi();
const commandServerApi = await getCommandServerApi();

Expand Down
28 changes: 27 additions & 1 deletion src/testUtil/toPlainObject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Position, Range, Selection } from "vscode";
import { Selection, Position, Range, TextEditor } from "vscode";
import { TestDecoration } from "../core/editStyles";
import type { Target } from "../typings/target.types";
import { Token } from "../typings/Types";
Expand All @@ -13,6 +13,13 @@ export type RangePlainObject = {
end: PositionPlainObject;
};

export type RangePlainObjectWithOffsets = {
start: PositionPlainObject;
end: PositionPlainObject;
startOffset: number;
endOffset: number;
};

export type SelectionPlainObject = {
anchor: PositionPlainObject;
active: PositionPlainObject;
Expand Down Expand Up @@ -60,6 +67,25 @@ export function rangeToPlainObject(range: Range): RangePlainObject {
};
}

/**
* Like `rangeToPlainObject`, but also includes the document character offsets.
*
* This is mainly for ease of implementation inside of other editors.
* @param range
* @param editor
*/
export function rangeToPlainObjectWithOffsets(
range: Range,
editor: TextEditor
): RangePlainObjectWithOffsets {
return {
start: positionToPlainObject(range.start),
end: positionToPlainObject(range.end),
startOffset: editor.document.offsetAt(range.start),
endOffset: editor.document.offsetAt(range.end),
};
}

export function selectionToPlainObject(
selection: Selection
): SelectionPlainObject {
Expand Down
Loading