Skip to content

Conversation

@vasily-kirichenko
Copy link
Contributor

_1

Copy link
Contributor

@KevinRansom KevinRansom left a comment

Choose a reason for hiding this comment

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

Thanks

| _ -> None
findBestPositionToInsertOpenDeclaration modules scope point entity
| _ ->
// we failed to find insertion point because ast is empty for some reason, return top left point in this case
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to do this anytime there is an empty ast?
What if we have a comment at the top of the file with open declarations below it? Would that mean the new open declaration will go above the comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, could we find out why the ast is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if we have a comment at the top of the file with open declarations below it? Would that mean the new open declaration will go above the comment?

Yes. Or maybe on top of the comment. Why?

Also, could we find out why the ast is empty?

Why? We cannot find a position to insert the open statement, that's enough. Or you suggest to fix the parser?..

Copy link
Contributor

Choose a reason for hiding this comment

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

@TIHan

I looked at this, and it seems like the right fix to me, tryFindNearestPointAndModules is looking for the nearest open so that it can insert the new one below it, and finds none.

In findNearestPointToInsertOpenDeclaration when no open was found it quite reasonably says. Oh well, I couldn't find anywhere to insert the open, I guess I will use the top of the file.

It might be interesting to skip over leading comments, but that is a new feature and is not the intent of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Skipping over comments would be not be trivial as we don't retain comments in the AST.

The reasoning why I mentioned it was because I thought the AST was giving us nothing even if we had open declarations, and we would just shove a open declaration at the top of the others, potentially skipping a comment if there was one there. However, I misinterpreted this. The case he is fixing is when there are no open declarations, which makes this fix absolutely fine.

Copy link
Contributor

@TIHan TIHan Jun 1, 2018

Choose a reason for hiding this comment

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

@vasily-kirichenko Thank you for your continued work.

In the future, I recommend being more descriptive in the PRs rather than only showing a GIF. A GIF is great, but we need context.

| _ -> None
findBestPositionToInsertOpenDeclaration modules scope point entity
| _ ->
// we failed to find insertion point because ast is empty for some reason, return top left point in this case
Copy link
Contributor

Choose a reason for hiding this comment

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

@TIHan

I looked at this, and it seems like the right fix to me, tryFindNearestPointAndModules is looking for the nearest open so that it can insert the new one below it, and finds none.

In findNearestPointToInsertOpenDeclaration when no open was found it quite reasonably says. Oh well, I couldn't find anywhere to insert the open, I guess I will use the top of the file.

It might be interesting to skip over leading comments, but that is a new feature and is not the intent of this PR.

Copy link
Contributor

@TIHan TIHan left a comment

Choose a reason for hiding this comment

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

I misinterpreted what this does. Yes, we should put the open at the top of the file if we can't find any open declarations. Judging from the comment, it didn't sound like that; it sounded more broken rather than just not finding any open declarations.

But now that I understand, this is perfectly reasonable.

@KevinRansom KevinRansom merged commit a8d516a into dotnet:master Jun 1, 2018
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Jan 26, 2022
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