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

Feature Request: OpenTextDocument with content #21413

Closed
hoovercj opened this issue Feb 25, 2017 · 8 comments
Closed

Feature Request: OpenTextDocument with content #21413

hoovercj opened this issue Feb 25, 2017 · 8 comments
Assignees
Labels
api feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@hoovercj
Copy link
Member

hoovercj commented Feb 25, 2017

#12283 added an api overload to open a new, untitled text document with an optional language mode.

It would be great if this could be augmented to accept content.

Use case: I have an extension that ships with examples. Currently I have to do one of the following:

  • Open the "source" file directly which would allow users to clobber it
  • Copy the file to a temp file and open that and then remember to clean it up. Users would still have to "save as" to save it in a location that is useful to them
  • Use the new overload to open an untitled, empty text document and then use an edit to populate the contents.

The last one is the most viable but seems unnecessary. I would like to see openTextDocument(options?: {language: id, content: text}) so I could do something like

openTextDocument(exampleUri).then(exampleDocument => { const exampleText = exampleDocument.getText(); openTextDocument({language: LANG_ID, content: exampleText})
@bpasero
Copy link
Member

bpasero commented Feb 25, 2017

@hoovercj why are steps 1 and 2 needed if all you need is the content of a file?

@hoovercj
Copy link
Member Author

Sorry @bpasero for the poorly worded issue, I've updated it to clarify that those were 3 distinct options.

@bpasero
Copy link
Member

bpasero commented Feb 25, 2017

@hoovercj nothing prevents you from opening an untitled file and then setting the content, right?

@roblourens roblourens added the info-needed Issue requires more information from poster label Feb 25, 2017
@hoovercj
Copy link
Member Author

hoovercj commented Feb 27, 2017

@bpasero I didn't see a way to set the content without doing an insert textedit which would allow the user to undo the text which goes against the spirit of the "open example" command that I've exposed and the "open untitled document with content" that I've proposed.

From the user perspective, "open example" should be a discrete step. If they make some modifications and want to quickly get back to the original document they can't blindly press "undo" right now because they would get back to a blank page and then have to press "redo" and hope they don't accidentally press a key and then lose the document and need to "open example" again.

Of course, if there is a different way that I've missed to set the document content that doesn't result in an undo, I might be able to use that instead

@bpasero
Copy link
Member

bpasero commented Feb 27, 2017

Ok, good point about the undo.

@bpasero bpasero added api feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster labels Feb 27, 2017
@bpasero
Copy link
Member

bpasero commented Feb 27, 2017

@jrieken fyi

I think we would be open to a PR here if you are willing to look into it.

@jrieken jrieken self-assigned this Feb 27, 2017
@jrieken jrieken added the help wanted Issues identified as good community contribution opportunities label Feb 27, 2017
@jrieken
Copy link
Member

jrieken commented Feb 27, 2017

Yeah, would be straight forward to pass on a string when calling the open function

@isidorn
Copy link
Contributor

isidorn commented Mar 28, 2017

@jrieken please verify

@isidorn isidorn added the verification-needed Verification of issue is requested label Mar 28, 2017
@jrieken jrieken added the verified Verification succeeded label Mar 28, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants