Skip to content

Commit 27b1d93

Browse files
committed
feat: add codeintel cmdlets
1 parent b62a037 commit 27b1d93

12 files changed

+621
-19
lines changed

PSSourcegraph.psd1

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,29 @@
6262
# Type files (.ps1xml) to be loaded when importing this module
6363
TypesToProcess = @(
6464
'src/Types/Search.Types.ps1xml'
65+
'src/Types/Location.Types.ps1xml'
66+
'src/Types/Repository.Types.ps1xml'
6567
)
6668

6769
# Format files (.ps1xml) to be loaded when importing this module
6870
FormatsToProcess = @(
6971
'src/Formats/Search.Format.ps1xml'
72+
'src/Formats/Hover.Format.ps1xml'
73+
'src/Formats/Location.Format.ps1xml'
7074
)
7175

7276
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
7377
# NestedModules = @()
7478

7579
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
7680
FunctionsToExport = @(
77-
'Disable-SourcegraphRepository',
78-
'Enable-SourcegraphRepository',
79-
'Get-SourcegraphRepository',
80-
'Get-SourcegraphUser',
81-
'Invoke-SourcegraphApiRequest',
82-
'New-SourcegraphUser',
81+
'Get-SourcegraphRepository'
82+
'Get-SourcegraphHover'
83+
'Get-SourcegraphDefinition'
84+
'Get-SourcegraphReference'
85+
'Get-SourcegraphUser'
86+
'Invoke-SourcegraphApiRequest'
87+
'New-SourcegraphUser'
8388
'Search-Sourcegraph'
8489
)
8590

@@ -91,12 +96,13 @@
9196

9297
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
9398
AliasesToExport = @(
94-
'Disable-SrcRepository',
95-
'Enable-SrcRepository',
96-
'Get-SrcRepositories',
99+
'Get-SrcRepository',
100+
'Get-SrcHover',
101+
'Get-SrcDefinition',
102+
'Get-SrcReference',
97103
'Get-SrcUser',
98-
'Invoke-SrcApiRequest',
99104
'New-SrcUser',
105+
'Invoke-SrcApiRequest',
100106
'Search-Src'
101107
)
102108

PSSourcegraph.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Import-Module "$PSScriptRoot/src/api.psm1"
22
Import-Module "$PSScriptRoot/src/repos.psm1"
33
Import-Module "$PSScriptRoot/src/users.psm1"
44
Import-Module "$PSScriptRoot/src/search.psm1"
5+
Import-Module "$PSScriptRoot/src/codeintel.psm1"

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@ Install-Module PSSourcegraph
2020

2121
## Included
2222

23-
- `Search-Sourcegraph` with autocompletion
24-
- `Disable-SourcegraphRepository`
25-
- `Enable-SourcegraphRepository`
26-
- `Get-SourcegraphRepository`
27-
- `Get-SourcegraphUser`
28-
- `New-SourcegraphUser`
29-
- `Invoke-SourcegraphApiRequest`
23+
Use `Get-Help` to see documentation for any command.
24+
25+
- **Search**
26+
- `Search-Sourcegraph` 💡 _with query autocompletion_
27+
- **Code intelligence**
28+
💡 _All code intelligence cmdlets support search output as pipeline input_
29+
- `Get-SourcegraphHover`
30+
- `Get-SourcegraphDefinition`
31+
- `Get-SourcegraphReference`
32+
- **Repositories**
33+
- `Get-SourcegraphRepository`
34+
- **Users**
35+
- `Get-SourcegraphUser`
36+
- `New-SourcegraphUser`
37+
- **Utility**
38+
- `Invoke-SourcegraphApiRequest`
3039

3140
Missing something? Please file an issue!
3241

src/Formats/Hover.Format.ps1xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Configuration>
2+
<ViewDefinitions>
3+
<View>
4+
<Name>HoverMarkdown</Name>
5+
<ViewSelectedBy>
6+
<TypeName>Sourcegraph.Hover</TypeName>
7+
</ViewSelectedBy>
8+
<CustomControl>
9+
<CustomEntries>
10+
<CustomEntry>
11+
<CustomItem>
12+
<ExpressionBinding>
13+
<ScriptBlock>
14+
(ConvertFrom-Markdown -InputObject $_.markdown.text -AsVT100EncodedString).VT100EncodedString
15+
</ScriptBlock>
16+
</ExpressionBinding>
17+
</CustomItem>
18+
</CustomEntry>
19+
</CustomEntries>
20+
</CustomControl>
21+
</View>
22+
</ViewDefinitions>
23+
</Configuration>

src/Formats/Location.Format.ps1xml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Configuration>
3+
<Controls>
4+
<Control>
5+
<Name>SourcegraphLocationGroupingFormat</Name>
6+
<CustomControl>
7+
<CustomEntries>
8+
<CustomEntry>
9+
<CustomItem>
10+
<Frame>
11+
<CustomItem>
12+
<ExpressionBinding>
13+
<ScriptBlock>
14+
try {
15+
$rev = if ($_.Resource.Commit.Oid) {
16+
# AbbreviatedOid causes panics if queried for search results
17+
"@`e[02m$($_.Resource.Commit.Oid.Substring(0, 7))`e[0m"
18+
} else {
19+
""
20+
}
21+
"`e[036m$($_.Resource.Repository.Name)`e[0m$rev > `e[035m$($_.Resource.Path)`e[0m"
22+
} catch {
23+
$_ | Out-String | Write-Warning
24+
}
25+
</ScriptBlock>
26+
<!-- Does not work because of https://github.com/PowerShell/PowerShell/issues/7744 -->
27+
<!-- <ScriptBlock>
28+
try {
29+
$rev = if ($_.FileMatch.File.Commit.Oid) {
30+
$commitUrl = "$($_.FileMatch.Repository.Url)@$($_.FileMatch.File.Commit.Oid)"
31+
# AbbreviatedOid causes panics if queried for search results
32+
# TODO figure out why the link does not work (but works with Out-String)
33+
" @ `e]8;;$commitUrl`a`e[02m$($_.FileMatch.File.Commit.Oid.Substring(0, 7))`e[0m`e]8;;`a"
34+
} else {
35+
""
36+
}
37+
"`e]8;;$($_.FileMatch.Repository.Url)`a`e[036m$($_.FileMatch.Repository.Name)`e[0m`e]8;;`a$rev > `e]8;;$($_.FileMatch.File.Url)`a`e[035m$($_.FileMatch.File.Path)`e[0m`e]8;;`a"
38+
} catch {
39+
$_ | Out-String | Write-Warning
40+
}
41+
</ScriptBlock> -->
42+
</ExpressionBinding>
43+
</CustomItem>
44+
</Frame>
45+
</CustomItem>
46+
</CustomEntry>
47+
</CustomEntries>
48+
</CustomControl>
49+
</Control>
50+
</Controls>
51+
<ViewDefinitions>
52+
<View>
53+
<Name>Location</Name>
54+
<ViewSelectedBy>
55+
<TypeName>Sourcegraph.Location</TypeName>
56+
</ViewSelectedBy>
57+
<GroupBy>
58+
<ScriptBlock>
59+
$_.Resource.Repository.Name + $_.Resource.Commit.Oid + $_.Resource.Path
60+
</ScriptBlock>
61+
<CustomControlName>SourcegraphLocationGroupingFormat</CustomControlName>
62+
</GroupBy>
63+
<TableControl>
64+
<TableHeaders>
65+
<TableColumnHeader>
66+
<Label>Range</Label>
67+
</TableColumnHeader>
68+
<TableColumnHeader>
69+
<Label>Url</Label>
70+
</TableColumnHeader>
71+
</TableHeaders>
72+
<TableRowEntries>
73+
<TableRowEntry>
74+
<TableColumnItems>
75+
<TableColumnItem>
76+
<ScriptBlock>
77+
try {
78+
$range = $_.Range
79+
"$($range.Start.Line + 1):$($range.Start.Character + 1)-$($range.End.Line + 1):$($range.End.Character + 1)"
80+
} catch {
81+
$_ | Out-String | Write-Warning
82+
}
83+
</ScriptBlock>
84+
</TableColumnItem>
85+
<TableColumnItem>
86+
<ScriptBlock>
87+
# Shorten commit hash
88+
$url = $_.Url -replace '@([a-f0-9]{7})[a-f0-9]{33}/-/','@$1/-/'
89+
if ($env:TERM_PROGRAM -eq 'vscode') {
90+
# Link detector in VS Code doesn't detect links with "@" properly
91+
$url = $url -replace '@','%40'
92+
}
93+
$url
94+
</ScriptBlock>
95+
</TableColumnItem>
96+
</TableColumnItems>
97+
</TableRowEntry>
98+
</TableRowEntries>
99+
</TableControl>
100+
</View>
101+
</ViewDefinitions>
102+
</Configuration>

src/Types/Location.Types.ps1xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Types>
3+
<Type>
4+
<Name>Sourcegraph.Location</Name>
5+
<Members>
6+
<!-- Convenience aliases to allow easier selection of common properties through Select-Object -Property -->
7+
<ScriptProperty>
8+
<Name>RepositoryName</Name>
9+
<GetScriptBlock>$this.Resource.Repository.Name</GetScriptBlock>
10+
</ScriptProperty>
11+
<ScriptProperty>
12+
<Name>FilePath</Name>
13+
<GetScriptBlock>$this.Resource.Path</GetScriptBlock>
14+
</ScriptProperty>
15+
<ScriptProperty>
16+
<Name>CommitID</Name>
17+
<GetScriptBlock>$this.Resource.Commit.Oid</GetScriptBlock>
18+
</ScriptProperty>
19+
<ScriptProperty>
20+
<Name>LineNumber</Name>
21+
<GetScriptBlock>$this.Range.Start.Line</GetScriptBlock>
22+
</ScriptProperty>
23+
<ScriptProperty>
24+
<Name>CharacterNumber</Name>
25+
<GetScriptBlock>$this.Range.Start.Character</GetScriptBlock>
26+
</ScriptProperty>
27+
</Members>
28+
</Type>
29+
</Types>

src/Types/Repository.Types.ps1xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Types>
2+
<Type>
3+
<Name>Sourcegraph.Repository</Name>
4+
<Members>
5+
<AliasProperty>
6+
<Name>RepositoryName</Name>
7+
<ReferencedMemberName>Name</ReferencedMemberName>
8+
</AliasProperty>
9+
</Members>
10+
</Type>
11+
</Types>

src/Types/Search.Types.ps1xml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<Types>
33
<Type>
44
<Name>Sourcegraph.LineMatch</Name>
55
<Members>
6-
<!-- Convenience aliases to allow easier selection of common properties through Select-Object -Property -->
6+
<!-- Convenience aliases to allow piping to codeintel cmdlets -->
77
<ScriptProperty>
88
<Name>RepositoryName</Name>
99
<GetScriptBlock>$this.FileMatch.Repository.Name</GetScriptBlock>
@@ -16,6 +16,36 @@
1616
<Name>CommitID</Name>
1717
<GetScriptBlock>$this.FileMatch.File.Commit.Oid</GetScriptBlock>
1818
</ScriptProperty>
19+
<ScriptProperty>
20+
<Name>CharacterNumber</Name>
21+
<GetScriptBlock>$this.offsetAndLengths | ForEach-Object { $_[0] }</GetScriptBlock>
22+
</ScriptProperty>
23+
</Members>
24+
</Type>
25+
<Type>
26+
<Name>Sourcegraph.Symbol</Name>
27+
<Members>
28+
<!-- Convenience aliases to allow piping to codeintel cmdlets -->
29+
<ScriptProperty>
30+
<Name>RepositoryName</Name>
31+
<GetScriptBlock>$this.FileMatch.Repository.Name</GetScriptBlock>
32+
</ScriptProperty>
33+
<ScriptProperty>
34+
<Name>FilePath</Name>
35+
<GetScriptBlock>$this.FileMatch.File.Path</GetScriptBlock>
36+
</ScriptProperty>
37+
<ScriptProperty>
38+
<Name>CommitID</Name>
39+
<GetScriptBlock>$this.FileMatch.File.Commit.Oid</GetScriptBlock>
40+
</ScriptProperty>
41+
<ScriptProperty>
42+
<Name>LineNumber</Name>
43+
<GetScriptBlock>$this.Location.Range.Start.Line</GetScriptBlock>
44+
</ScriptProperty>
45+
<ScriptProperty>
46+
<Name>CharacterNumber</Name>
47+
<GetScriptBlock>$this.Location.Range.Start.Character</GetScriptBlock>
48+
</ScriptProperty>
1949
</Members>
2050
</Type>
2151
</Types>

0 commit comments

Comments
 (0)