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

SearchEditor: Open new editor with args #95582

Closed
wansa9 opened this issue Apr 18, 2020 · 12 comments
Closed

SearchEditor: Open new editor with args #95582

wansa9 opened this issue Apr 18, 2020 · 12 comments
Assignees
Labels
feature-request Request for new features or functionality search-editor verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@wansa9
Copy link

wansa9 commented Apr 18, 2020

I'd like to define a keybinding to open a new search editor with args like workbench.action.findInFiles. The following is what I want to define:

    {
        "key": "ctrl+shift+g",
        "command": "search.action.openNewEditor",
        "args": {
            "query": "${selectedText}",
            "filesToInclude": "${relativeFileDirname}"
        },
        "when": "editorTextFocus"
    }

Context: I work on a project which has a lot of files and directories. "Find in Files" takes a long time so I want to limit search target under a specified directory. #95420 is similar but I want to open search editors for different directories so "search.searchEditor.experimental.reusePriorSearchConfiguration": true doesn't fit my cases.

@JacksonKearl
Copy link
Contributor

search.action.openNewEditor and search.action.openNewEditorToSide can now be called with args like:

{
	query: string,
	includes: string,
	excludes: string,
	contextLines: number,
	wholeWord: boolean,
	caseSensitive: boolean,
	regexp: boolean,
	useIgnores: boolean,
	showIncludesExcludes: boolean,
}

@JacksonKearl
Copy link
Contributor

JacksonKearl commented May 7, 2020

Note that while "query": "${selectedText}", works, the ${selectedText} variable throws if there's no selected text. By default search editors use selected text anyways, so you can just leave this out to use selected text if it exists and nothing otherwise.

@ArturoDent
Copy link

I note that there is no intellisense for the args as of

Version: 1.46.0-insider (user setup)
Commit: 2b472d1e4aaaecdda5ca96289869f90ae82de3a1
Date: 2020-05-11T10:00:12.459Z
Electron: 7.2.4
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.19624

Nor is an error indicated if I omit the args key as in

   {
      "key": "alt+g",
      "command": "search.action.openNewEditor",
      "query": "flatten",
      "regexp": true,
    },

@JacksonKearl
Copy link
Contributor

@ArturoDent unfortunately intellisense and advanced schema validation for keybinding arguments is not supported for any commands.

@ArturoDent
Copy link

Hmmm, maybe I'm talking about something different things?

keybinding intellisense

@JacksonKearl
Copy link
Contributor

JacksonKearl commented May 11, 2020

oh cool. added

seems like adoption is pretty limited. other commands I tried didnt have any intellisense

@usernamehw
Copy link
Contributor

usernamehw commented May 11, 2020

If you know of any commands that accept arguments in keybindings.json but don't have IntelliSense then you could create issues for those commands.

@dufferzafar
Copy link

dufferzafar commented May 14, 2020

@JacksonKearl Thank you for this!

I'm using this to build a "saved search" for all my TODOs, like so:

    {
        "key": "alt+k alt+t",
        "command": "search.action.openNewEditor",
        "args": {
            "query": "(TODO|NOTE|BUG):",
            "regexp": true
        },
        "when": "editorTextFocus"
    }

Now, this launches the search editor with the input box focused and the "query" selected.
After which I have to press enter to actually run the search.
And then, click the search results part to focus that area so I can use Arrow Keys / Page Up/Down to browse the results.

I want two little improvements - perform the search automatically - don't wait for me to press Enter.

And, when you've already run the search, just focus the search results for me - avoiding the need to click that area.

I suppose they could implemented as other optional arguments? performSearch: true and focusResults: true.

@JacksonKearl
Copy link
Contributor

JacksonKearl commented May 14, 2020

@dufferzafar that sounds like a good idea (have you tried out contextLines btw?), but could you open a separate issue? It’s much easier to manage work items as issues versus issue comments

@dufferzafar
Copy link

Yeah, I tried contextLines as well, but I seem to like the initial value of 0 for this particular use case.

Issue opened: #97823

@JacksonKearl JacksonKearl added verification-needed Verification of issue is requested and removed verification-needed Verification of issue is requested labels Jun 1, 2020
@roblourens roblourens added the verified Verification succeeded label Jun 3, 2020
@ArturoDent
Copy link

ArturoDent commented Jun 7, 2020

Sorry for the late comment before presumed release, but just today I discovered that you can do something similar with the workbench.action.findInFiles command. Namely:

{
  "key": "ctrl+shift+f",
  "command": "workbench.action.findInFiles",
  "args": {
    "query": "(conc)a.",
    "replace": "boy $1 howdy",
    "triggerSearch": true,
    "filesToInclude": "",
    "isRegex": true 
  }
}

The args for this command are here:

export interface IFindInFilesArgs {
query?: string;
replace?: string;
triggerSearch?: boolean;
filesToInclude?: string;
filesToExclude?: string;
isRegex?: boolean;
isCaseSensitive?: boolean;
matchWholeWord?: boolean;
}

Notice that some of the args are different and some the same as those proposed above:

{
	query: string,
	includes: string,
	excludes: string,
	contextLines: number,
	wholeWord: boolean,
	caseSensitive: boolean,
	regexp: boolean,
	useIgnores: boolean,
	showIncludesExcludes: boolean,
}

I know that is in search/browser/searchActions.ts but it works in the standalone version of vscode if search/browser was meant to signify it wouldn't necessarily?

I would think that for consistency purposes they should be same where possible, especially since they both can be used in keybindings.

Also note that the workbench.action.findInFiles version contains a triggerSearch arg which is very nice.

[I am also a little bummed that I just discovered this today thanks to https://stackoverflow.com/questions/62251045/workbench-view-search-vs-workbench-action-findinfiles-commands-in-vscode and that these commands are not reflected in intellisense (I'll open a new issue).]

@JacksonKearl
Copy link
Contributor

#97823 is about triggering search when running the keybinding.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality search-editor verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants