-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing file path for saving new files from chat in windows #6489
base: main
Are you sure you want to change the base?
Conversation
fileName = defaultUriPath.fileName.toString() | ||
VfsUtil.findFile(defaultUriPath.parent, true) | ||
try { | ||
val defaultUriPath = Paths.get(params.defaultUri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultUri
is a URI so it should be parsed into a path like this
Paths.get(URI.create(params.defaultUri))
This has accidentally worked on other platforms because it assumes file://
is part of the path name. Wrapping in try/catch won't fix the root problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olafurpg maybe it's a good time to rewrite agent API to use Path
objects instead of strings? There is quite a few corner cases in the way paths can be encoded (especially on windows) and discrepancies between agent and client path parsing hit us many times in past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the auto-generated bindings? We encode these as TypeScript string
on the cody side and don't have a static type to distinguish between URIs and normal strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For good and bad, we rely on JSON.stringify
, which doesn't expose hooks to customize serialization of URI
instances, so we need to rely on some form of discipline
52b4cee
to
f9d3a2c
Compare
* Normalizes a URI string to a consistent format across platforms. | ||
*/ | ||
@JvmStatic | ||
fun normalizeUri(uriString: String): URI { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not really returning normalised URI, just a normal one.
You would have to call .normalize()
on it at the end to make that true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you created a normalizeUri
method which converts stinf to URI but you are not using it anywhere in your code?
fun toPath(uriString: String): Path = | ||
Paths.get(normalizeUri(uriString)) | ||
|
||
@JvmStatic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not encourage using API which operates on strings in jetbrains.
One should always convert to URI
and then compare the objects directly.
And for that we should have tests.
Solves Linear issue
Problem
On Windows systems, file operations were failing due to incorrect URI handling, specifically:
This resulted in errors like:
Solution
Added proper Windows path normalization in CodyEditorUtil.kt to handle file paths correctly before URI creation:
Added path normalization for Windows-style paths:
Applied this normalization in both findFileOrScratch and createFileOrScratchFromUntitled methods
Test plan
Changelog