-
Notifications
You must be signed in to change notification settings - Fork 512
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
Changes from 1 commit
47ccd39
0198d8f
2fdb3e8
a65f946
cc04b7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,12 @@ export namespace CloseFileRequest { | |
'editor/closeFile'); | ||
} | ||
|
||
export namespace SaveFileRequest { | ||
export const type = | ||
new RequestType<string, EditorOperationResponse, void, void>( | ||
'editor/saveFile'); | ||
} | ||
|
||
export namespace ShowErrorMessageRequest { | ||
export const type = | ||
new RequestType<string, EditorOperationResponse, void, void>( | ||
|
@@ -239,14 +245,18 @@ export class ExtensionCommandsFeature implements IFeature { | |
NewFileRequest.type, | ||
filePath => this.newFile()); | ||
|
||
this.languageClient.onRequest( | ||
this.languageClient.onRequest( | ||
OpenFileRequest.type, | ||
filePath => this.openFile(filePath)); | ||
|
||
this.languageClient.onRequest( | ||
CloseFileRequest.type, | ||
filePath => this.closeFile(filePath)); | ||
|
||
this.languageClient.onRequest( | ||
SaveFileRequest.type, | ||
filePath => this.saveFile(filePath)); | ||
|
||
this.languageClient.onRequest( | ||
ShowInformationMessageRequest.type, | ||
message => this.showInformationMessage(message)); | ||
|
@@ -408,6 +418,36 @@ export class ExtensionCommandsFeature implements IFeature { | |
return promise; | ||
} | ||
|
||
private saveFile(filePath: string): Thenable<EditorOperationResponse> { | ||
|
||
var promise: Thenable<EditorOperationResponse>; | ||
|
||
// Make sure the file path is absolute | ||
if (!path.win32.isAbsolute(filePath)) | ||
{ | ||
filePath = path.win32.resolve( | ||
vscode.workspace.rootPath, | ||
filePath); | ||
} | ||
|
||
// 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Very good point. I actually grabbed that from: 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 commentThe 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 commentThe 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. |
||
{ | ||
promise = | ||
vscode.workspace.openTextDocument(filePath) | ||
.then(doc => doc.save()) | ||
.then(_ => EditorOperationResponse.Completed); | ||
} | ||
else | ||
{ | ||
promise = Promise.resolve(EditorOperationResponse.Completed); | ||
} | ||
|
||
return promise; | ||
} | ||
|
||
private setSelection(details: SetSelectionRequestArguments): EditorOperationResponse { | ||
vscode.window.activeTextEditor.selections = [ | ||
new vscode.Selection( | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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
overvar
.let
is properly blocked scoped in JavaScript. I'm commenting on this one line about it but there are quite a fewvar
usages in this PR that should belet
.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 :)