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

Get help for cmdlet #47

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Get help for cmdlet #47

wants to merge 3 commits into from

Conversation

corbob
Copy link
Member

@corbob corbob commented Jul 10, 2019

resolves #26

Adding the powerShell/showHelp message.

This currently only gets help for the function test. This is the framework to get it working. Next step is determining what to send to PSES. I suspect we could do like vscode-powershell and if in Visual mode, send the contents of the highlight, if in a normal mode, then we get the current word (with expansion across the hyphen).

Does not work at the moment. Need to debug the PSES side of it? I think...
Turns out was sending an object when it just wants a string.
Still need to figure out what string to get... I think this would make sense to be done like vscode-powershell.

async function getCurrentSelection(mode: string) {
let doc = await workspace.document

// This doesn't actually get the selection... It gets the lines... As though the mode was V-LINE and not VISUAL...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TylerLeonhardt or @yatli Was it intentional to get the lines instead of the selection? I was hoping to use getCurrentSelection for the Get-Help wrapper in that we could get the selected command, but we can't if we get the whole line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you like to get the word under the cursor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well yes, but also in my mind getCurrentSelection would be to get the currently selected text when in VISUAL mode.

Given the line:

Write-Host this is a test

a selection of Write-Host would ideally return just Write-Host. As it is currently, it returns the entire line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah unfortunately, @yatli had to hack the getCurrentSelection method to work (it works pretty well!). coc.nvim supplies a “get current selection” equivalent but I couldn’t get it to work and requires some work to get an idea for what’s going wrong:
neoclide/coc.nvim#933

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe, we should distinguish mode "v" from "V"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell there are effectively 3 Visual modes: V-LINE ("V"), V-BLOCK ("Ctrl+v"), and VISUAL ("v"). Should we distinguish between V-Block and normal Visual? I would think in V-Block mode, we'd want to get from start to end and possibly ignore that it's a block (for evaluation I can't think of a scenario where we would want to evaluate just the block).

Copy link
Member

@yatli yatli Jul 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a second thought and realized this:

Executing a part of something would be dangerous.
I wouldn't want someone to execute:

[[rm -rf /]]foo/bar

Line-based eval is good because it will never be a part of something (because of the line escape symbol `

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, so for evaluation then line based makes sense. Perhaps I'll either create a get-help specific one, or add a mode specific to Get-Help. As using Get-Help you'll not want the entire line, but just the selected command.

@yatli
Copy link
Member

yatli commented Jul 13, 2019

Curious, what's the difference between showHelp and onHover?
A few VSCode extensions now support "info pane" which places help info in a persistent window -- guess showHelp is similar?

Edit: if that's the thing, then I'll definitely map it to <F1>! :D

@corbob
Copy link
Member Author

corbob commented Jul 13, 2019

Curious, what's the difference between showHelp and onHover?

showHelp sends a string to PSES which then evaluates it against Get-Help with -ShowOnline so it will open the online help. If there is no online help (or we can't reach the online help URI) then it will just output into the PSIC

@yatli
Copy link
Member

yatli commented Jul 13, 2019

thanks for the explanation.
I just played with it for a few commands, but it keeps landing on a 404 page.
For example:
Get-Help -Online Get-ChildItem

gets me: https://docs.microsoft.com/en-us/powershell/module/4.0/microsoft.powershell.core/providers/FileSystem-Provider/Get-ChildItem-for-Filesystem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add command: powershell.searchOnlineHelp
3 participants