Closed pelikhan closed 3 weeks ago
/genai-describe
/genai-review
The changes in the GIT_DIFF show that the developer is refactoring the code to use a new method toUri
from the host
object to create URIs instead of using vscode.Uri.file
. This is a good change as it centralizes the URI creation logic in one place, making the code more maintainable.
However, there is a potential issue with the toUri
method. It checks if the input string is an absolute path or a URL, but it does not handle relative paths. If a relative path is passed to this method, it will be treated as an absolute path, which could lead to incorrect URIs.
Here is a suggested fix:
toUri(filenameOrUrl: string): vscode.Uri {
const folder = this.projectUri;
if (!filenameOrUrl) return folder;
if (/^[a-z][a-z0-9+\-.]*:\/\//.test(filenameOrUrl))
return vscode.Uri.parse(filenameOrUrl, true);
if (this.path.isAbsolute(filenameOrUrl))
return vscode.Uri.file(filenameOrUrl);
else return vscode.Uri.file(path.join(folder.fsPath, filenameOrUrl));
}
This fix uses the path.join
method to correctly handle relative paths.
Other than this issue, the changes look good. The developer has also removed some commented-out code, which is a good practice as it keeps the codebase clean.
So, with the above fix, LGTM :rocket:
generated by pr-review
vscode.Uri.parse
function now includes a second argument,true
, which allows parsing of URLs with strict mode enabled. This change affects multiple files includingbrowser.ts
,state.ts
, andvshost.ts
. ๐applyEdits
function inedit.ts
now accepts an additional argument,state
, which is an instance ofExtensionState
. This change also affects the way URIs are created in the function. ๐activateFragmentCommands
function infragmentcommands.ts
and other similar functions now use thehost.toUri
method to create URIs instead ofvscode.Uri.file
. This change is also reflected in multiple other files. ๐ExtensionState
class instate.ts
has been significantly refactored. A large block of error handling code has been removed, and thesaveScripts
andapplyEdits
methods now use thehost.toUri
method. ๐งนactivateStatusBar
function instatusbar.ts
now uses thehost
property ofstate
to create URIs. ๐activateTestController
function intestcontroller.ts
now uses thehost.toUri
method to create URIs. ๐ฎtoUri
, has been added to theVSCodeHost
class invshost.ts
. This method creates avscode.Uri
from a filename or URL. ๐In summary, these changes seem to centralize the creation of URIs in the
VSCodeHost
class, making the code more maintainable and consistent. ๐ฏ