11using EnvDTE ;
2+ using EnvDTE80 ;
23using Microsoft . SqlServer . TransactSql . ScriptDom ;
34using Microsoft . VisualStudio . Shell ;
45using SQLScriptsExplorer . Addin . Repository ;
@@ -12,6 +13,15 @@ namespace SQLScriptsExplorer.Addin.Infrastructure
1213{
1314 public static class DocumentManager
1415 {
16+ private static DTE2 DTE
17+ {
18+ get
19+ {
20+ ThreadHelper . ThrowIfNotOnUIThread ( ) ;
21+ return Package . GetGlobalService ( typeof ( DTE ) ) as DTE2 ;
22+ }
23+ }
24+
1525 public static void OpenTemplate ( string fileName , string fileFullPath )
1626 {
1727 try
@@ -21,9 +31,10 @@ public static void OpenTemplate(string fileName, string fileFullPath)
2131 if ( File . Exists ( fileFullPath ) )
2232 {
2333 string fileContent = File . ReadAllText ( fileFullPath ) ;
34+ var docName = Path . GetFileNameWithoutExtension ( fileName ) ;
35+ var docExtension = Path . GetExtension ( fileName ) ;
2436
25- DTE dte = Package . GetGlobalService ( typeof ( DTE ) ) as DTE ;
26- var fileDocument = dte . ItemOperations . NewFile ( @"General\Text File" , fileName ) . Document ;
37+ var fileDocument = DTE . ItemOperations . NewFile ( @"General\Text File" , $ "{ docName } _Copy{ docExtension } ") . Document ;
2738
2839 TextSelection textSelection = fileDocument . Selection as TextSelection ;
2940 textSelection . SelectAll ( ) ;
@@ -48,12 +59,9 @@ public static void EditTemplate(string fileName, string fileFullPath)
4859 {
4960 try
5061 {
51- ThreadHelper . ThrowIfNotOnUIThread ( ) ;
52-
5362 if ( File . Exists ( fileFullPath ) )
5463 {
55- DTE dte = Package . GetGlobalService ( typeof ( DTE ) ) as DTE ;
56- dte . ItemOperations . OpenFile ( fileFullPath ) ;
64+ DTE . ItemOperations . OpenFile ( fileFullPath ) ;
5765 }
5866 else
5967 {
@@ -66,20 +74,16 @@ public static void EditTemplate(string fileName, string fileFullPath)
6674 }
6775 }
6876
69- public static void ExecuteTemplate ( string fileName , string fileFullPath , bool confirmScriptExecution )
77+ public static void ExecuteTemplate ( string fileName , string fileFullPath )
7078 {
7179 string CMD_QUERY_EXECUTE = "Query.Execute" ;
7280
7381 try
7482 {
75- ThreadHelper . ThrowIfNotOnUIThread ( ) ;
76-
77- DTE dte = Package . GetGlobalService ( typeof ( DTE ) ) as DTE ;
78-
7983 // Ensure the document we are executing is the document we have opened by checking its name
80- if ( dte . ActiveDocument != null && dte . ActiveDocument . ProjectItem . Name . Equals ( fileName ) )
84+ if ( DTE . ActiveDocument != null && DTE . ActiveDocument . ProjectItem . Name . Equals ( fileName ) )
8185 {
82- dte . ExecuteCommand ( CMD_QUERY_EXECUTE ) ;
86+ DTE . ExecuteCommand ( CMD_QUERY_EXECUTE ) ;
8387 }
8488 }
8589 catch ( Exception ex )
@@ -92,13 +96,9 @@ public static void FormatSelection()
9296 {
9397 try
9498 {
95- ThreadHelper . ThrowIfNotOnUIThread ( ) ;
96-
97- DTE dte = Package . GetGlobalService ( typeof ( DTE ) ) as DTE ;
98-
99- if ( dte . ActiveDocument != null )
99+ if ( DTE . ActiveDocument != null )
100100 {
101- TextSelection selection = ( TextSelection ) dte . ActiveDocument . Selection ;
101+ TextSelection selection = ( TextSelection ) DTE . ActiveDocument . Selection ;
102102
103103 // Format whole text: selection.SelectAll();
104104 string selectedText = selection . Text ;
@@ -150,7 +150,15 @@ private static string FormatSelectionUsingSQLServer(string code)
150150
151151 private static Tuple < TSqlParser , SqlScriptGenerator > GetSQLParser ( string targetVersion )
152152 {
153- if ( targetVersion == "SQL Server 2019" )
153+ if ( targetVersion == "SQL Server 2025" )
154+ {
155+ return new Tuple < TSqlParser , SqlScriptGenerator > ( new TSql170Parser ( false ) , new Sql170ScriptGenerator ( ) ) ;
156+ }
157+ else if ( targetVersion == "SQL Server 2022" )
158+ {
159+ return new Tuple < TSqlParser , SqlScriptGenerator > ( new TSql160Parser ( false ) , new Sql160ScriptGenerator ( ) ) ;
160+ }
161+ else if ( targetVersion == "SQL Server 2019" )
154162 {
155163 return new Tuple < TSqlParser , SqlScriptGenerator > ( new TSql150Parser ( false ) , new Sql150ScriptGenerator ( ) ) ;
156164 }
0 commit comments