@@ -218,13 +218,28 @@ export class GoDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
218
218
219
219
// Stitch the results together to make the results look like
220
220
// go-outline.
221
- // TODO(suzmue): use regexp to find the package declaration.
221
+ let pkgDeclRng = new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 0 ) ) ;
222
+ let pkgName = '' ;
223
+
224
+ // Try to find the package statement.
225
+ const text = document . getText ( ) ;
226
+ const packageStatement = new RegExp ( '^[ \\t]*package[ \\t]*(\\S+)' , 'm' ) ;
227
+ const match = packageStatement . exec ( text ) ;
228
+ if ( match && match . length === 2 ) {
229
+ const packageDecl = match [ 0 ] ;
230
+ const start = text . indexOf ( packageDecl ) ;
231
+ pkgDeclRng = new vscode . Range (
232
+ document . positionAt ( start ) ,
233
+ document . positionAt ( start + packageDecl . length )
234
+ ) ;
235
+ pkgName = packageDecl [ 1 ] ;
236
+ }
222
237
const packageSymbol = new vscode . DocumentSymbol (
223
- 'unknown' ,
238
+ pkgName ,
224
239
'package' ,
225
240
vscode . SymbolKind . Package ,
226
- new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 0 ) ) ,
227
- new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 0 ) )
241
+ pkgDeclRng ,
242
+ pkgDeclRng
228
243
) ;
229
244
packageSymbol . children = symbols ;
230
245
if ( this . includeImports ) {
0 commit comments