forked from Lencerf/vscode-beancount
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add beta version of outline for Lencerf#25
- Loading branch information
1 parent
08e6667
commit 5600f7f
Showing
4 changed files
with
71 additions
and
7 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,45 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
export class SymbolProvider implements vscode.DocumentSymbolProvider { | ||
private format(tokens: string[]): string { | ||
const name = []; | ||
|
||
for (let j = 0; j < tokens.length; j++) { | ||
const element = tokens[j]; | ||
if ( | ||
element.startsWith('*') || | ||
element === ';#region' || | ||
element === ';#endregion' | ||
) { | ||
continue; | ||
} | ||
name.push(element); | ||
} | ||
return name.join(' '); | ||
} | ||
|
||
provideDocumentSymbols( | ||
document: vscode.TextDocument, | ||
token: vscode.CancellationToken | ||
): Promise<vscode.DocumentSymbol[]> { | ||
return new Promise((resolve, reject) => { | ||
const symbols: vscode.DocumentSymbol[] = []; | ||
for (let i = 0; i < document.lineCount; i++) { | ||
const line = document.lineAt(i); | ||
|
||
// line can start or end with ;#region | ||
if (line.text.includes(';#region')) { | ||
const symbol = new vscode.DocumentSymbol( | ||
this.format(line.text.split(' ')), | ||
'Region', | ||
vscode.SymbolKind.String, | ||
line.range, | ||
line.range | ||
); | ||
symbols.push(symbol); | ||
} | ||
} | ||
resolve(symbols); | ||
}); | ||
} | ||
} |