This project has moved and is read-only. For the latest updates, please go here.

Is it possible to get PTVS have a SQL Server like execution mode for highlighted code?

Feb 23, 2015 at 7:12 PM
In SQL Server, I am used to highlighting a block of code and then hitting F5 to then execute the SQL block of code highlighted. I have spent more time coding in Spyder and I have this ability of opening some scripts and running a section of code I have in the docstring where I have documented my scripts with examples of how to run my code so this limitation in VS annoying.

It seems PTVS is more of a tool for fully fledged developers who are writing code for production and not for intermittent programmers who run smaller code blocks manually. At the moment, I am highlighting the block of code and then hitting Ctrl+E twice (very annoying) as this way the code goes to the interpreter, but it would be useful to have the SQL type behaviour (where you run the code block selected in the Interactive session) or assign a convenient function key?

If there is some configuration that can achieve this, then please include in your next video.
Feb 23, 2015 at 7:16 PM

as someone that has used spyder, we'd love to learn about all the features you'd love to see in PTVS. the most effective method is to file bug/feature requests and we can address as time allows. but as a whole, we'll be enhancing PTVS's REPL and other interactive feature quite a bit in the next couple of releases.
Feb 23, 2015 at 7:19 PM
I'm not sure I understand why Ctrl+E,Ctrl+E is annoying compared to some other key combination. Could you explain for me the difference in behaviour, or maybe show a link to the SQL Server behaviour (I don't use SQL Server, so I'm not sure what you're referring to here)?

We have also recently fixed some bugs around not correctly trimming indentation when using Ctrl+E, Ctrl+E, so if that's a major annoyance then it will be going away in PTVS 2.2.

You are correct though that PTVS is targeting developers working on projects more than those working on shorter snippets of code. This is largely inherited from Visual Studio, which is very much focused on projects. For the next version of PTVS after 2.2 we want to swing this focus back the other way and try and help out people who want a lighter-weight Python environment, so suggestions are very welcome, but we probably won't get to them for our current release.
Feb 23, 2015 at 7:20 PM
You can reassign the shortcut in Tools -> Options -> Environment -> Keyboard. The command name is Python.SendSelectionToInteractive.

Can you clarify what you mean by "SQL type behaviour (where you run the code block selected in the Interactive session)"? You can simply type code in the Interactive Window to execute it.
Feb 23, 2015 at 7:23 PM
pavel, I think he wants to highlight code in the Editor, press a single key, not three, and have it executed. we need a general, "execute-selected-code as described by user <here>" feature. one of which may then be send selected code to REPL.
Feb 23, 2015 at 8:11 PM
It can be easily rebound to a single key. The only reason why we don't do it out of the box is because there is a severe shortage of keys, and they're all used already by something else in VS.

Implementing send-to-REPL from an arbitrary text selection anywhere in VS is pretty much impossible. At best we can do it for an arbitrary text editor (and I think we already do that).
Feb 23, 2015 at 11:28 PM
I think you chaps have identified the issue.

If you look at most of the scientific stack (Rstudio, Spyder, I am sure Matlab but cant remember as I dont have a license now), and even the Sys Admin IDE's (Powershell ISE, SQL Server SSMS), all these systems have the concept of being able to highlight a section of code and run just that piece selected.

FYI, I think one of the biggest differences between professional coders and proficient infrequent scientific coders is that the latter probably prefer the interactive environment as they code iteratively. The feedback from the REPL interpreter provides confidence inducing way points to build up the code base. This may include needing to visualize the output or inputs within the function to check the dimensionality. Moreover, once the script have taken shape, then most will introduce some form of a docstring, and I certainly include a few examples in my functions. I imagine full time hard core developers to write 100's of lines of code without needing to engage the feedback loop - I guess its a matter of style.

Under my slower type of development process, hopefully you can see that sending small fragments of code to the IPython REPL by issuing Ctrl+E sequence, gets very repetitive and would justify a 'hot-key' remapping. Personally, as I use solutions / projects as a container to keep related work, there is no concept of an 'entry point' into the project. Imagine that you are pricing difficult securities on an infrequent basis, but want to keep similar pricing endeavors together so that you can audit and review investment decisions made. Sure in time, once the process becomes sufficiently frequent and you have amassed sufficient experience, a more architected solution can be designed where the concepts learned within the various pricing analysis can be aggregated into a unified framework.

May I recommend that it could be worth checking in with the scientific community and seeing if any of this resonates? Personally, I would really make use of
  1. A setting in the PTVS configuration that allows me to change the F5 'run' behaviour so that if a section of code is selected, then this code is executed via the interactive IPython session. (please see F5 vs F8 in Powershell IDE or SQL Server Management Studio F5 for Microsoft technologies that adopt this).
  2. Not all Projects or Solutions have a single entry point as they can also be a collection of related idea or similar exercises repeated through time stored in individual date stamped files.
I have only been using VS2013 with PTVS for 1 day, the tool looks very promising.

If I could ask, when you chaps get around to organizing your next big version roll out, please could you show some WPF examples (either using IronPython or as it would be nice to see some not too complicated but definitely not simple examples if they already exist. I appreciate most people are slowly migrating to web based applications, but I still think there is sufficient mileage in desktop applications which are currently undeserved by Python.

Thanks for the short-cut tip, I will take a look tomorrow when back at work.
Feb 23, 2015 at 11:47 PM
One thing that we keep remembering about occasionally is the concept of a default keyboard scheme & toolwindow layout. VS ships with a bunch (it asks you which you want to use when you start it for the first time, the option being "Generic", "C++", "C#" etc), but it can also be loaded via Tools -> Import and Export Settings. For your kind of scenario, we could make a different keymapping that reorganizes things in a more interactive-centric way, and provide a download with instructions. Better yet if we can put it in VS Gallery, but I don't think it supports .vssettings.

Note also that aside from Send to Interactive, you also have another "entrypoint-less" means of running code in your current open file, if you want to run the entire file that you're currently editing, as described here. You don't have to create a project at all if you do that, but the commands are still available when you do. I don't recall what shortcuts we define for those commands, but IIRC it was something like Shift+Ctrl+F5, so probably still not something super convenient for you, but this can also be changed to a simpler shortcut in a similar way.
Apr 2, 2015 at 1:53 PM
I think one thing to keep in mind is that Spyder or MATLAB go one step further: for interactive scripting, you break your script into sections using special comment markup (#%% in Spyder or %% in MATLAB). Then no matter where in the code section the cursor position is, the whole section can be executed with a keyboard shortcut. This has several advantages: it is very fast as there is no need to select a region of code. Also selecting exactly the same region of code repeatedly can be distracting and very boring. In addition, when you select a region of code you could accidentally press a "wrong" key and lose the code! Then you will have to press Undo, etc etc.

So I guess a more complete proposal would be to adopt or including a similar feature to Spyder's "Code Cells" (the #%% comment markup) in addition to the "Execute cell" and "Execute and advance to the next cell" command and the respective short-cuts.
Apr 2, 2015 at 6:11 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.