Skip to content
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

Merged
8 commits merged into from
Jun 25, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jun 18, 2018

Fixes #24882 and #24904

@ghost ghost requested review from sheetalkamat, amcasey and mjbvz June 18, 2018 18:50
@ghost ghost force-pushed the getEditsForFileRename_project branch 2 times, most recently from 07e2ad8 to e6fd848 Compare June 18, 2018 19:16
@ghost ghost force-pushed the getEditsForFileRename_project branch from e6fd848 to 5369b37 Compare June 18, 2018 19:59
Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

const oldProject = this.projectService.getDefaultProjectForFile(oldFilePath);
if (oldProject) return { file: oldFilePath, project: oldProject };

const newFilePath = toNormalizedPath(args.newFilePath);
Copy link
Member

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).

if (!scriptInfo) {
return Errors.ThrowNoProject();
getDefaultProjectForFile(fileName: NormalizedPath, ensureProject = false): Project | undefined {
const scriptInfo = this.getScriptInfoForNormalizedPath(fileName);
Copy link
Member

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?

Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking with #25058

Copy link
Author

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.

Copy link
Member

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

@@ -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;
Copy link
Member

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?

Copy link
Author

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

Copy link
Author

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.

});
if (!scriptInfo) return undefined;
const file = toNormalizedPath(scriptInfo.path);
return { file, project: this.ensureDefaultProjectForFile(file) };
Copy link
Member

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.

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats this change for ?

Copy link
Author

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.

Copy link
Member

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.

if (!scriptInfo) {
return Errors.ThrowNoProject();
getDefaultProjectForFile(fileName: NormalizedPath, ensureProject = false): Project | undefined {
const scriptInfo = this.getScriptInfoForNormalizedPath(fileName);
Copy link
Member

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.

@ghost
Copy link
Author

ghost commented Jun 19, 2018

@sheetalkamat Please re-review

@ghost
Copy link
Author

ghost commented Jun 19, 2018

Latest commit fixes #25058


const changes: (protocol.FileCodeEdits | FileTextChanges)[] = [];
this.projectService.forEachProject(project => {
for (const fileTextChanges of project.getLanguageService().getEditsForFileRename(oldPath, newPath, formatOptions, preferences)) {
Copy link
Member

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?

Copy link
Member

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?

Copy link
Author

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?

Copy link
Member

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

Copy link
Author

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.

@ghost ghost merged commit 878bf80 into master Jun 25, 2018
@ghost ghost deleted the getEditsForFileRename_project branch June 25, 2018 18:00
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants