-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Implement go-to-definition for dot-sourced files * Support $PSScriptRoot in dot-sourced files * Add PathUtils for unified path normalization
- Loading branch information
Showing
10 changed files
with
195 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,49 @@ | ||
// | ||
// 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; | ||
using System.Runtime.InteropServices; | ||
|
||
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> | ||
internal static readonly char AlternatePathSeparator = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? '/' : '\\'; | ||
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 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 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 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 | ||
}; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/PowerShellEditorServices.Test.Shared/References/DotSources.ps1
This file contains 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,15 @@ | ||
. ./ReferenceFileE.ps1 | ||
. "$PSScriptRoot/ReferenceFileE.ps1" | ||
. "${PSScriptRoot}/ReferenceFileE.ps1" | ||
. './ReferenceFileE.ps1' | ||
. "./ReferenceFileE.ps1" | ||
. .\ReferenceFileE.ps1 | ||
. '.\ReferenceFileE.ps1' | ||
. ".\ReferenceFileE.ps1" | ||
. ReferenceFileE.ps1 | ||
. 'ReferenceFileE.ps1' | ||
. "ReferenceFileE.ps1" | ||
. ./dir/../ReferenceFileE.ps1 | ||
. ./invalidfile.ps1 | ||
. "" | ||
. $someVar |
4 changes: 2 additions & 2 deletions
4
test/PowerShellEditorServices.Test.Shared/References/ReferenceFileB.ps1
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
. .\ReferenceFileC.ps1 | ||
. "$PSScriptRoot\ReferenceFileC.ps1" | ||
|
||
Get-ChildItem | ||
|
||
My-Function "testb" | ||
My-Function "testb" |
This file contains 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