@@ -5,6 +5,7 @@ import { Logger } from './logger';
55import { SourceControl } from './sourceControl' ;
66import { DocumentInfoProvider } from './documentInfoProvider' ;
77import { Settings } from './../settings' ;
8+ import { ModulePathInfo } from './languages/modulePathToUriConverters' ;
89
910export interface EditorInfo {
1011 workspaceUri ?: vscode . Uri ;
@@ -29,80 +30,68 @@ export class EditorHelper {
2930 private _documentInfoProvider : DocumentInfoProvider ,
3031 ) { }
3132
32- public async goToFileAndLine ( editorInfo ?: EditorInfo )
33- {
33+ public async goToFileAndLine ( editorInfo ?: EditorInfo ) {
3434 if ( ! editorInfo ?. workspaceUri ) {
3535 return ;
3636 }
3737
3838 const workspaceUri = editorInfo . workspaceUri ;
3939 const lineNumber = editorInfo . lineNumber ?? 0 ;
4040
41- try
42- {
41+ try {
4342 let doc : vscode . TextDocument | undefined = undefined ;
4443
45- if ( ! await utils . fileExists ( workspaceUri ) )
46- {
44+ if ( ! await utils . fileExists ( workspaceUri ) ) {
4745 doc = await this . askAndOpenFromSourceControl ( editorInfo ) ;
4846 }
49- else
50- {
47+ else {
5148 doc = await vscode . workspace . openTextDocument ( workspaceUri ) ;
5249
5350 const txtLine = doc . lineAt ( lineNumber - 1 ) ;
54- var fileChanged :boolean = false ;
55- if ( editorInfo . executedCode ) {
51+ let fileChanged :boolean = false ;
52+ if ( editorInfo . executedCode ) {
5653 fileChanged = ( txtLine . text . trim ( ) !== editorInfo . executedCode ) ;
5754 }
5855 else {
5956 try {
60- var sourceDoc = await this . getFromSourceControl ( workspaceUri , editorInfo . lastInstanceCommitId ! ) ;
61- if ( sourceDoc ) {
57+ const sourceDoc = await this . getFromSourceControl ( workspaceUri , editorInfo . lastInstanceCommitId ! ) ;
58+ if ( sourceDoc ) {
6259 fileChanged = ( txtLine . text . trim ( ) !== sourceDoc . lineAt ( lineNumber - 1 ) . text . trim ( ) ) ;
6360 }
64- else {
61+ else {
6562 return ;
6663 }
6764 }
68- catch ( exeption ) {
65+ catch ( exeption ) {
6966 await vscode . window . showWarningMessage (
7067 'Cannot locate file in source control. Please make sure its checked in' ) ;
7168 }
72-
73-
7469 }
75- if ( fileChanged )
76- {
70+ if ( fileChanged ) {
7771 doc = await this . askAndOpenFromSourceControl ( editorInfo ) ; ;
7872 }
79- else
80- {
73+ else {
8174 const docInfo = await this . _documentInfoProvider . getDocumentInfo ( doc ) ;
8275 const methodInfos = docInfo ?. methods || [ ] ;
83- if ( methodInfos . all ( m => m . symbol . name != editorInfo . functionName ) )
84- {
76+ if ( methodInfos . all ( m => m . symbol . name != editorInfo . functionName ) ) {
8577 doc = await this . askAndOpenFromSourceControl ( editorInfo ) ;
8678 }
8779 }
8880 }
8981
90- if ( doc )
91- {
82+ if ( doc ) {
9283 await this . openFileAndLine ( doc , lineNumber ) ;
9384 }
9485 }
95- catch ( error )
96- {
86+ catch ( error ) {
9787 Logger . error ( `Failed to open file: ${ editorInfo . modulePhysicalPath } ` , error ) ;
9888 vscode . window . showErrorMessage ( `Failed to open file: ${ editorInfo . modulePhysicalPath } ` )
9989 }
10090 }
10191
102- public async openTextDocumentFromUri ( uri : vscode . Uri ) : Promise < vscode . TextDocument > {
92+ public async openTextDocumentFromUri ( uri : vscode . Uri ) : Promise < vscode . TextDocument > {
10393 let doc = await vscode . workspace . openTextDocument ( uri ) ;
10494 return doc ;
105-
10695 }
10796
10897 public async openFileAndLine ( doc : vscode . TextDocument , lineNumber : number ) {
@@ -117,18 +106,16 @@ export class EditorHelper {
117106 return await vscode . window . showTextDocument ( doc ) ;
118107 }
119108
120- private async askAndOpenFromSourceControl ( editorInfo : EditorInfo ) : Promise < vscode . TextDocument | undefined >
121- {
122- if ( ! this . _sourceControl . current )
123- {
109+ private async askAndOpenFromSourceControl ( editorInfo : EditorInfo ) : Promise < vscode . TextDocument | undefined > {
110+ if ( ! this . _sourceControl . current ) {
124111 const sel = await vscode . window . showWarningMessage (
125112 'File version is different from the version recorded in this flow.\nPlease configure source control.' ,
126113 'configure' ) ;
127- if ( sel == 'configure' )
114+ if ( sel == 'configure' ) {
128115 await vscode . commands . executeCommand ( "workbench.action.openWorkspaceSettings" , { query : Settings . sourceControl . key } ) ;
116+ }
129117 }
130- else
131- {
118+ else {
132119 let sel = await vscode . window . showWarningMessage (
133120 `File version is different from the version recorded in this flow, would you like to open the remote version of the file' installed.` ,
134121 'yes'
@@ -155,54 +142,32 @@ export class EditorHelper {
155142 return await this . _sourceControl . current ?. getFile ( uri , commit ) ;
156143 }
157144
158-
159- public async getWorkspaceFileUri ( editorInfo : EditorInfo ) : Promise < vscode . Uri | undefined > {
160-
161- const moduleLogicalPath = editorInfo . moduleLogicalPath ;
162- //Try first using the logical name of the function if we have it
163- if ( moduleLogicalPath ) {
164-
165- var symbols = await this . lookupCodeObjectByFullName ( moduleLogicalPath ) ;
166- //We have a match
167- if ( symbols . length === 1 ) {
168- return symbols [ 0 ] . location . uri ;
169- }
145+ public async getWorkspaceFileUri (
146+ pathInfo : ModulePathInfo ,
147+ document ?: vscode . TextDocument ,
148+ ) : Promise < vscode . Uri | undefined > {
149+ if ( ! document ) {
150+ return ;
170151 }
171152
172- const modulePhysicalPath = editorInfo . modulePhysicalPath ;
173- if ( modulePhysicalPath ) {
174-
175- const moduleRootFolder = modulePhysicalPath . split ( '/' ) . firstOrDefault ( ) ;
176- const moduleWorkspace = vscode . workspace . workspaceFolders ?. find ( w => w . name === moduleRootFolder ) ;
177- if ( moduleWorkspace ) {
178-
179- const workspaceUri = moduleWorkspace
180- ? vscode . Uri . joinPath ( moduleWorkspace . uri , '..' , modulePhysicalPath )
181- : undefined ;
182-
183- return workspaceUri ;
184- }
185- else {
186- const file = await ( await vscode . workspace . findFiles ( modulePhysicalPath ) ) . firstOrDefault ( ) ;
187- return file ;
188- }
189-
190-
153+ const languageExtractor = await this . _documentInfoProvider . symbolProvider . getSupportedLanguageExtractor ( document ) ;
154+ if ( ! languageExtractor ) {
155+ return ;
191156 }
192157
193-
194- }
158+ const converters = await languageExtractor . getModulePathToUriConverters ( ) ;
159+ let path ;
160+ for ( let index = 0 ; ! path && index < converters . length ; index ++ ) {
161+ const converter = converters [ index ] ;
162+ path = await converter . convert ( pathInfo ) ;
163+ }
195164
196- private async lookupCodeObjectByFullName ( name :string ) : Promise < vscode . SymbolInformation [ ] > {
197- return await vscode . commands . executeCommand ( "vscode.executeWorkspaceSymbolProvider" , name ) ;
165+ return path ;
198166 }
199167
200-
201-
202-
203168 public async getExecutedCodeFromScm ( uri : vscode . Uri , commit : string , line : integer ) : Promise < string | undefined > {
204- var doc = await this . getFromSourceControl ( uri , commit ) ;
205- if ( doc ) {
169+ const doc = await this . getFromSourceControl ( uri , commit ) ;
170+ if ( doc ) {
206171 return doc . lineAt ( line - 1 ) . text . trim ( ) ;
207172 }
208173 }
0 commit comments