-
Notifications
You must be signed in to change notification settings - Fork 513
add .Save() to FileContext API #1139
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
Conversation
src/features/ExtensionCommands.ts
Outdated
// Normalize file path case for comparison | ||
var normalizedFilePath = filePath.toLowerCase(); | ||
|
||
if (vscode.workspace.textDocuments.find(doc => doc.fileName.toLowerCase() == normalizedFilePath)) |
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.
Careful here. On Linux, the file system is case-sensitive so this test could find the wrong file. Probably need to do a runtime check of the OS or file-system. I wonder if there is some function in node's OS or Path modules that could help?
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.
Very good point. I actually grabbed that from:
https://github.com/PowerShell/vscode-powershell/blob/master/src/features/ExtensionCommands.ts#L393
So I'll update that as well. Perhaps we should still normalize on Windows?
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.
Windows and I think macOS, right? Doesn't it also have a case-insensitive file system?
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.
Ah. I didn't know macOS was case-insensitive! I'll fix the if-check.
src/features/ExtensionCommands.ts
Outdated
var normalizedFilePath = this.normalizeFilePath(filePath); | ||
|
||
// since Windows is case-insensitive, we need to normalize it differently | ||
var canFind = vscode.workspace.textDocuments.find(doc => { |
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.
Probably also good to make this its own function to avoid duplication
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.
Yep. Looks much cleaner now. Thanks!
@rkeithhill when you sign off, I'll get this merged in 😄 |
src/features/ExtensionCommands.ts
Outdated
|
||
private findTextDocument(filePath: string): boolean { | ||
// since Windows and macOS are case-insensitive, we need to normalize them differently | ||
var canFind = vscode.workspace.textDocuments.find(doc => { |
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.
tslint will complain if doc
isn't in parens (doc)
. I've started work with tslint but man, there is soo much change. And somewhere along the line my lint warning fixes broke various commands. Anyway, we should still probably try to avoid adding new stuff for the linter to complain about. :-)
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.
Fixed!
src/features/ExtensionCommands.ts
Outdated
|
||
if (vscode.workspace.textDocuments.find(doc => doc.fileName.toLowerCase() == normalizedFilePath)) | ||
var promise: Thenable<EditorOperationResponse>; |
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.
Another linter thing and something @daviwil espoused as well - favor the use of let
over var
. let
is properly blocked scoped in JavaScript. I'm commenting on this one line about it but there are quite a few var
usages in this PR that should be let
.
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.
Fixed all occurrences in the file :)
src/features/ExtensionCommands.ts
Outdated
} else { | ||
docPath = doc.fileName; | ||
} | ||
return docPath == filePath; |
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.
Probably want to use a ===
here to prevent any type coercion although both should be strings. I tend to favor ===
and !==
unless I know I want the comparison to do some type coercion for me. See https://stackoverflow.com/questions/359494/which-equals-operator-vs-should-be-used-in-javascript-comparisons
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.
fixed!
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.
LGTM
Thanks @rkeithhill and @daviwil! |
This is the VSCode portion of this change. See the PSES portion here: PowerShell/PowerShellEditorServices#590
Please let me know if I'm missing something.
To test this, you can use:
$psEditor.GetEditorContext().CurrentFile.Save()
in the Integrated Console.