SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Auto add parameters for functions

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
Auto add parameters for functions
Author Message
ezhovea



Joined: 07 Jul 2016
Posts: 9
Country: Russian Federation

Post Auto add parameters for functions Reply with quote
Dears, would you please explain, may the following behaviour changed somehow.

For example, I have a function on SQL Server instance:
Code:
use tempdb
go
create function dbo.f_test(@p1 int, @p2 datetime)
returns datetime
as
begin
   return @p2;
end;
go


If I type "select dbo." a drop down list with matching objects will be shown. When I select the required function from the list and press Enter, the code it will be automatically completed as follows: "select dbo.f_test(v_p1, v_p2)" and pointer will be placed to the end of the string.
I would like to change this behaviour and do not add this part (v_p1, v_p2).

Can it be configured somehow?

BR, Evgeniy
SL Assistant 12.2.387, SSMS 18.12.1, SQL Server 2019
Wed Nov 08, 2023 5:27 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
Please try Shift+Enter instead of Enter, that should insert name only.
Wed Nov 08, 2023 2:20 pm View user's profile Send private message
ezhovea



Joined: 07 Jul 2016
Posts: 9
Country: Russian Federation

Post Reply with quote
SysOp wrote:
Please try Shift+Enter instead of Enter, that should insert name only.


Is it possible to set proposed behaviour as ByDefault?

Anyway, thank you very much, it can be a solution, even I have to change my habit )
BR, Evgeniy
Fri Nov 10, 2023 9:18 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
Just in case, Shift+Enter is not specific to functions, it's a hot key for inserting text without expansion, for example, if you want to add a table name to INSERT statement, but don't automatically insert table columns and value placeholder fields at the same time, you can use Shift+Enter. It also works in other places as well. Enter (or Tab) is for a full code completion, Shift+Enter for a simple name completion only.
Sat Nov 11, 2023 4:19 am View user's profile Send private message
ezhovea



Joined: 07 Jul 2016
Posts: 9
Country: Russian Federation

Post Reply with quote
SysOp wrote:
Just in case, Shift+Enter is not specific to functions, it's a hot key for inserting text without expansion, for example, if you want to add a table name to INSERT statement, but don't automatically insert table columns and value placeholder fields at the same time, you can use Shift+Enter. It also works in other places as well. Enter (or Tab) is for a full code completion, Shift+Enter for a simple name completion only.

Ok, thank you very much.
Would you please consider, does it make sense to parameterize this behaviour?
While writing code, after the assistant has automatically added “stubs” for function parameters, I have to go back and replace the automatically added text (v_p1, v_p2) with the parameter names/values.
It is much faster to do this directly while writing code, for example after entering a comma, or when entering "(" after the function name (This is how it works now when entering the function name manually or via Shift+Enter).
I understand, I am not a single user of your product :) but please, take a look on it once more from my angle.
BR, Evgeniy
Wed Nov 15, 2023 5:00 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
It might be a matter of taste or a use case. Let's imagine a function with a dozen or more dozen parametes. It's not easy to remember them, ames positions, in/out, etc... that feature was implemented long ago based on user feedback and asking. To accomodate different needs we support two different hotkeys for different use cases..

If you wish, you can remove functions from intellisense options and implement your own using code snippets, for example, using $OBJECT(...)$ and or other macros.
Wed Nov 15, 2023 5:29 am View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 2109

Post Reply with quote
The application code constructing and inserting the code for the selected function could use the settings for Auto Expand Placeholders, instead of the plain "v_" + parameter name. These comments can be either selected or deleted directly (depending on the setting Action for Formatted Comments). This way you would have the best of both worlds, having both the parameters expanded and there as a reminder, while not having to manually delete anything since as soon as the caret touches those comments they can be overwritten without any further action (either select or manually delete) required from the user.

As we're already suggesting feature enhancements, let me add another two cents: adding an option that allows configuring the format of the placeholders inserted by this code. Different people have different habits. Mine is that I hate writing. I also rarely call procedures or invoke functions by passing constants as parameters, it's normally some variable that gets passed. Even when it's a constant, it's extremely likely it is encapsulated in a variable and those variables tend to bear the same name as the parameter for the functions, usually with some prefixes or suffixes. I kinda feel the "pain" ezhovea experiences. SA inserts the following code for a procedure or a function:

Code:

EXECUTE [dbo].[my_procedure] @param1 = null, @param2 = null

SELECT [dbo].[my_function](v_my_param1, v_my_param2)


If I understand correctly, ezhovea wants those v_my_param1 and v_my_param2 strings not to be inserted into the code, in order not to have them removed before anything can be put in their places. Inserting /*{ v_my_param1 }*/ instead would still show what these parameters are (although they are also hinted after the opening parenthesis or a comma), and would not be an obstruction when replacing them with actual values. Having the cursor at the end of the line would still prove to be an issue as you'd have to go backward to enter the parameters (or move the caret to the first parameter before editing them). Alternatively, the code could also move the caret to the first parameter, because I guess that's what most users do most of the time. My own experience is that I do that almost always.

On the other hand, having a setting that allows telling SA what to put there (a value, a NULL, a formatted column, or some other combination eg. "@lv_" + $NAMA$) could generate code that would not require any post-processing in most cases. Well, at least for me. I'm also aware that most users do not use SA the way I do so I'd completely understand if you would not want to implement this (probably overspecialized) feature. But I still think wrapping the parameter names in those formatted comments instead of inserting plain strings would be a relatively small and effective enhancement.

I also think this could be done by a user defined snippet. I'll try to build one when I have time to do so.
Sat Nov 18, 2023 5:43 am View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.