forked from asciidoctor/asciidoctor-vscode
-
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.
WIP - suuport inlay for Attribute value
resolves asciidoctor#731 Signed-off-by: Aurélien Pupier <[email protected]>
- Loading branch information
Showing
4 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { CancellationToken, Event, InlayHint, InlayHintKind, InlayHintsProvider, Position, ProviderResult, Range, TextDocument } from 'vscode' | ||
import { AsciidocParser } from '../asciidocParser' | ||
//import { AsciidocParser } from '../asciidocParser' | ||
|
||
export class AttributeInlayHintProvider implements InlayHintsProvider { | ||
onDidChangeInlayHints?: Event<void> | ||
provideInlayHints (textDocument: TextDocument, range: Range, _token: CancellationToken): ProviderResult<InlayHint[]> { | ||
const inlayHints: InlayHint[] = [] | ||
const startLine = range.start.line | ||
const endLine = range.end.line | ||
const document = AsciidocParser.load(textDocument) | ||
for (let index = startLine; index < endLine; index++) { | ||
const lineText = textDocument.lineAt(index).text | ||
console.log(lineText) | ||
const matches = /{[\w-]+}.*/.exec(lineText) | ||
if (matches !== null) { | ||
matches.forEach((value, index, array) => { | ||
console.log('###' + value + index + array) | ||
inlayHints.push(new InlayHint(new Position(index, lineText.indexOf(value) + value.length - 1), document.getAttribute(value))) | ||
}) | ||
} | ||
} | ||
return inlayHints | ||
} | ||
|
||
resolveInlayHint? (hint: InlayHint, _token: CancellationToken): ProviderResult<InlayHint> { | ||
return hint | ||
} | ||
} |
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,31 @@ | ||
import 'mocha' | ||
import * as vscode from 'vscode' | ||
import assert from 'assert' | ||
import { Position, Range } from 'vscode' | ||
import { AttributeInlayHintProvider } from '../features/attributeInlayHintProvider' | ||
|
||
let root | ||
|
||
suite('Attribute Inlay Hint Provider', () => { | ||
let createdFiles: vscode.Uri[] = [] | ||
setup(() => { | ||
root = vscode.workspace.workspaceFolders[0].uri.fsPath | ||
}) | ||
teardown(async () => { | ||
for (const createdFile of createdFiles) { | ||
await vscode.workspace.fs.delete(createdFile) | ||
} | ||
createdFiles = [] | ||
}) | ||
test('Should return attribute value as inlay', async () => { | ||
const fileWithInlayHint = vscode.Uri.file(`${root}/fileWithAttributeValueToInlay.adoc`) | ||
await vscode.workspace.fs.writeFile(fileWithInlayHint, Buffer.from(`:my-attribute-to-inlay: value to inlay | ||
{my-attribute-to-inlay} | ||
`)) | ||
createdFiles.push(fileWithInlayHint) | ||
|
||
const file = await vscode.workspace.openTextDocument(fileWithInlayHint) | ||
new AttributeInlayHintProvider().provideInlayHints(file, new Range(new Position(2, 0), new Position(2, 24)), undefined) | ||
}) | ||
}) |