-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make GetEditsForFileRenameRequestArgs not extend FileRequestArgs #25052
Conversation
07e2ad8
to
e6fd848
Compare
e6fd848
to
5369b37
Compare
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.
Thanks!
src/server/session.ts
Outdated
const oldProject = this.projectService.getDefaultProjectForFile(oldFilePath); | ||
if (oldProject) return { file: oldFilePath, project: oldProject }; | ||
|
||
const newFilePath = toNormalizedPath(args.newFilePath); |
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 don't know about the VS Code calling pattern, but VS will be making the request after the rename happens so I would expect the "new" code path to succeed much more often (i.e. might be worthwhile to check it first).
src/server/editorServices.ts
Outdated
if (!scriptInfo) { | ||
return Errors.ThrowNoProject(); | ||
getDefaultProjectForFile(fileName: NormalizedPath, ensureProject = false): Project | undefined { | ||
const scriptInfo = this.getScriptInfoForNormalizedPath(fileName); |
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 have guessed we'd want all projects for the path. Is that just out of scope for this PR?
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.
Do not change the public method's default here.
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.
Tracking with #25058
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.
This should return the same result as before if ensureProject
is provided, though previously it didn't have a default and was non-optional.
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.
The parameter ensureProject
was intentional so that we could ensure the passed in parameter and intent (syntactic/semantic/project update needed/not needed)etc
src/compiler/utilities.ts
Outdated
@@ -7494,7 +7494,11 @@ namespace ts { | |||
} | |||
} | |||
|
|||
// Reserved characters, forces escaping of any non-word (or digit), non-whitespace character. | |||
export function startsWithDirectory(path: string, dirPath: string): boolean { | |||
return tryRemoveDirectoryPrefix(path, dirPath) !== undefined; |
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.
Are the paths already in a form that accounts for platform case-sensitivity?
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.
Working on this in #24975
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, this PR never uses the function any more.
src/server/editorServices.ts
Outdated
}); | ||
if (!scriptInfo) return undefined; | ||
const file = toNormalizedPath(scriptInfo.path); | ||
return { file, project: this.ensureDefaultProjectForFile(file) }; |
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'm not sure I understand why we're calling ensureDefaultProjectForFile
. Is it to trigger a refresh? Otherwise, it seems like scriptInfo.getDefaultProject()
would suffice.
src/server/session.ts
Outdated
@@ -1454,7 +1466,7 @@ namespace ts.server { | |||
private createCheckList(fileNames: string[], defaultProject?: Project): PendingErrorCheck[] { | |||
return mapDefined<string, PendingErrorCheck>(fileNames, uncheckedFileName => { | |||
const fileName = toNormalizedPath(uncheckedFileName); | |||
const project = defaultProject || this.projectService.getDefaultProjectForFile(fileName, /*ensureProject*/ false); |
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.
Whats this change for ?
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.
Fixes some code that was fishy under --strictNullChecks
-- if the flag was passed this function returned a non-nullable type.
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.
No! Earlier change was correct because we do not want to update graph to get project at this point. We would do that after checklist is completed.
src/server/editorServices.ts
Outdated
if (!scriptInfo) { | ||
return Errors.ThrowNoProject(); | ||
getDefaultProjectForFile(fileName: NormalizedPath, ensureProject = false): Project | undefined { | ||
const scriptInfo = this.getScriptInfoForNormalizedPath(fileName); |
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.
Do not change the public method's default here.
@sheetalkamat Please re-review |
Latest commit fixes #25058 |
src/server/session.ts
Outdated
|
||
const changes: (protocol.FileCodeEdits | FileTextChanges)[] = []; | ||
this.projectService.forEachProject(project => { | ||
for (const fileTextChanges of project.getLanguageService().getEditsForFileRename(oldPath, newPath, formatOptions, preferences)) { |
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.
Do you need to exclude orphan projects or the configured projects which have no open file?
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 the projects with language service disabled?
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.
If the project has no files, getEditsForFileRename
should just return nothing. Should getLanguageService()
throw an error if the language service is disabled? Maybe we should have tryGetLanguageService()
that returns LanguageService | undefined
?
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.
getLanguageSevice will return language service all the time but it will be disabled (cleared semantic cache. I am working on changes where language service itself will know that its disabled but for now this info is in project and we should ignore those projects.)
For orphan projects, we are going through them unnecessarily no? we could avoid all that work by just ignoring these projects
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.
OK, we will now skip those projects.
Fixes #24882 and #24904