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

Fix index out-of-range exception when deleting script files #748

Merged
merged 3 commits into from
Sep 20, 2018

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Sep 18, 2018

Fixes #739.

  • Allows VSCode to send a request where the end line is 1 past the number of lines in the file.
  • Restores the old validation behaviour.
  • Adds a couple of tests.

@@ -197,7 +197,7 @@ public string[] ReferencedFiles
/// </summary>
/// <param name="text">Input string to be split up into lines.</param>
/// <returns>The lines in the string.</returns>
public static IList<string> GetLines(string text)
public static List<string> GetLines(string text)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realise this is a breaking change, but I without RemoveRange this gets trickier, and more importantly, less performant.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oof that's an odd one. Kind of seems like that shouldn't have been public.

I think it's a pretty safe bet that no one is using it... I would have never thought to look for a static get lines method on that class. That said, you could make an alternate private GetLinesInternal that is typed as List<string> then keep this method the same and have it implicitly cast to IList<string>

Either way, might consider decorating with Obsolete. That should probably either be moved to a utility class or just made private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get the impression that there are quite a few APIs exposed as public that really should be internal PSES, which is something I would ideally like to address with v2. It's a bit tricky because the way the project is broken up means some things need to be shared between libraries, but on the other hand those things are opportunities to design a real module API. But yeah, a lot of our public APIs I think need to be retired or changed.

/// <param name="isInsertion">If true, the position to validate is for an applied change.</param>
public void ValidatePosition(int line, int column, bool isInsertion)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similarly, this is also a breaking change -- so maybe we ought to keep it in? I'd prefer not personally, but the preference isn't that strong.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe have something like this?

public void ValidatePosition(int line, int column)
{
    // Actual logic
}

[Obsolete("Use ValidatePosition(int, int) instead")]
public void ValidatePosition(int line, int column, bool isInsertion)
{
    ValidatePosition(line, column);
}

I think it's worth avoiding the breaking change here, even if the risk is low.

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

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

I like this better. LGTM

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@rjmholt rjmholt merged commit 042f2e0 into PowerShell:master Sep 20, 2018
@rjmholt rjmholt deleted the index-oor-scriptfile-fix branch December 12, 2018 06:01
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.

4 participants