-
Notifications
You must be signed in to change notification settings - Fork 237
Fix #17: Add go to definition support for dot sourced file paths #786
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c1568fa
Implement go-to-definition for dot-sourced files
dee-see d865f3e
Merge branch 'master' into go-to-dot-sourced
TylerLeonhardt a2fc548
Fix code review issues
dee-see c774e7c
Replace preprocessor directive in PathUtils
dee-see 7507fec
Support $PSScriptRoot in dot-sourced files
dee-see 11a3107
Apply review suggestions
dee-see 5cd5061
Fix review issues
dee-see 0c1ea1f
Apply review suggestions
dee-see 49ec4a7
Remove unused `using`
dee-see File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System.IO; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Utility | ||
{ | ||
/// <summary> | ||
/// Utility to help handling paths across different platforms. | ||
/// </summary> | ||
/// <remarks> | ||
/// Some constants were copied from the internal System.Management.Automation.StringLiterals class. | ||
/// </remarks> | ||
internal static class PathUtils | ||
{ | ||
/// <summary> | ||
/// The default path separator used by the base implementation of the providers. | ||
/// | ||
/// Porting note: IO.Path.DirectorySeparatorChar is correct for all platforms. On Windows, | ||
/// it is '\', and on Linux, it is '/', as expected. | ||
/// </summary> | ||
internal static readonly char DefaultPathSeparator = Path.DirectorySeparatorChar; | ||
internal static readonly string DefaultPathSeparatorString = DefaultPathSeparator.ToString(); | ||
|
||
/// <summary> | ||
/// The alternate path separator used by the base implementation of the providers. | ||
/// | ||
/// Porting note: we do not use .NET's AlternatePathSeparatorChar here because it correctly | ||
/// states that both the default and alternate are '/' on Linux. However, for PowerShell to | ||
/// be "slash agnostic", we need to use the assumption that a '\' is the alternate path | ||
/// separator on Linux. | ||
/// </summary> | ||
#if CoreCLR | ||
dee-see marked this conversation as resolved.
Show resolved
Hide resolved
|
||
internal static readonly char AlternatePathSeparator = System.Management.Automation.Platform.IsWindows ? '/' : '\\'; | ||
#else | ||
internal static readonly char AlternatePathSeparator = '/'; | ||
#endif | ||
internal static readonly string AlternatePathSeparatorString = AlternatePathSeparator.ToString(); | ||
|
||
/// <summary> | ||
/// Converts all alternate path separators to the current platform's main path separators. | ||
/// </summary> | ||
/// <param name="path">The path to normalize.</param> | ||
/// <returns>The normalized path.</returns> | ||
public static string NormalizePathSeparators(string path) | ||
{ | ||
return string.IsNullOrWhiteSpace(path) ? path : path.Replace(AlternatePathSeparator, DefaultPathSeparator); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/PowerShellEditorServices.Test.Shared/Definition/FindsDotSourcedFile.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using Microsoft.PowerShell.EditorServices; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Test.Shared.Definition | ||
{ | ||
public class FindsDotSourcedFile | ||
{ | ||
public static readonly ScriptRegion SourceDetails = | ||
new ScriptRegion | ||
{ | ||
File = @"References\DotSources.ps1", | ||
StartLineNumber = 1, | ||
StartColumnNumber = 3 | ||
}; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/PowerShellEditorServices.Test.Shared/References/DotSources.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
. ./ReferenceFileE.ps1 | ||
. './ReferenceFileE.ps1' | ||
. "./ReferenceFileE.ps1" | ||
. .\ReferenceFileE.ps1 | ||
. '.\ReferenceFileE.ps1' | ||
. ".\ReferenceFileE.ps1" | ||
. ReferenceFileE.ps1 | ||
. 'ReferenceFileE.ps1' | ||
. "ReferenceFileE.ps1" | ||
. ./dir/../ReferenceFileE.ps1 | ||
. ./invalidfile.ps1 | ||
. "" | ||
. $someVar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.