Skip to content

Commit

Permalink
feat: refactor round 2, with shared context
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmu committed Apr 26, 2024
1 parent 557ab82 commit d6cf169
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 148 deletions.
47 changes: 47 additions & 0 deletions src/lib/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as vscode from 'vscode';
import { AllQPItemVariants, DisposablesMap } from '../types';
import { getConfig } from '../utils/getConfig';
import { ChildProcessWithoutNullStreams } from 'child_process';
import { highlightLineDecorationType } from '../utils/highlightLineDecorationType';

// simple context for each invoke of periscope search
let qp = vscode.window.createQuickPick<AllQPItemVariants>(); // @see https://code.visualstudio.com/api/references/vscode-api#QuickPick
let workspaceFolders = vscode.workspace.workspaceFolders;
let query = '';
let spawnRegistry: ChildProcessWithoutNullStreams[] = [];
let config = getConfig();
let rgMenuActionsSelected: string[] = [];
let highlightDecoration = highlightLineDecorationType();
let disposables: DisposablesMap = {
general: [],
rgMenuActions: [],
query: [],
};

export const context = {
resetContext,
qp,
workspaceFolders,
query,
spawnRegistry,
config,
rgMenuActionsSelected,
highlightDecoration,
disposables
};

// reset the context
function resetContext() {
context.qp = vscode.window.createQuickPick<AllQPItemVariants>();
context.workspaceFolders = vscode.workspace.workspaceFolders;
context.query = '';
context.spawnRegistry = [];
context.config = getConfig();
context.rgMenuActionsSelected = [];
context.highlightDecoration = highlightLineDecorationType();
context.disposables = {
general: [],
rgMenuActions: [],
query: [],
};
}
7 changes: 3 additions & 4 deletions src/lib/editorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import * as vscode from 'vscode';
import { previousActiveEditor, updatePreviousActiveEditor } from './editorContext';
import { activeQP } from './quickpickContext';
import { AllQPItemVariants, QPItemQuery } from '../types';
import { getConfig } from '../utils/getConfig';
import { highlightLineDecorationType } from '../utils/decorationType';
import {context as cx} from './context';

export function closePreviewEditor() {
if(previousActiveEditor) {
Expand Down Expand Up @@ -47,7 +46,7 @@ export function openNativeVscodeSearch(query: string, qp: vscode.QuickPick<AllQP
// remove the config suffix from the query
const trimmedQuery = query.slice(
0,
query.indexOf(getConfig().gotoNativeSearchSuffix)
query.indexOf(cx.config.gotoNativeSearchSuffix)
);

vscode.commands.executeCommand('workbench.action.findInFiles', {
Expand Down Expand Up @@ -78,6 +77,6 @@ export function openNativeVscodeSearch(query: string, qp: vscode.QuickPick<AllQP
const range = editor.document.lineAt(newPosition).range;
editor.selection = new vscode.Selection(newPosition, newPosition);
editor.revealRange(range, vscode.TextEditorRevealType.InCenter);
highlightLineDecorationType().set(editor);
cx.highlightDecoration.set(editor);
});
}
Loading

0 comments on commit d6cf169

Please sign in to comment.