|
| 1 | +import * as vscode from 'vscode'; |
| 2 | +import * as info from "./wordinfo"; |
| 3 | + |
| 4 | +class TasmHoverProvider implements vscode.HoverProvider { |
| 5 | + async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken) { |
| 6 | + let output:vscode.MarkdownString=new vscode.MarkdownString() |
| 7 | + let range = document.getWordRangeAtPosition(new vscode.Position(position.line, position.character)); |
| 8 | + if(range){ |
| 9 | + let word = document.getText(range).toLowerCase(); |
| 10 | + let char=/'(.)'/.exec(word) |
| 11 | + if(char) output.appendMarkdown(info.getcharMsg(char[1])); |
| 12 | + let keyword = info.GetKeyword(word) |
| 13 | + // let proc = findProc(word) |
| 14 | + // let macro = findMacro(word),label=findLabel(word); |
| 15 | + if(info.isNumberStr(word)){ |
| 16 | + output.appendMarkdown(info.getNumMsg(word));} |
| 17 | + // else if(proc !== undefined){ |
| 18 | + // output.appendCodeblock("assembly","(Procedure) " + proc.name) |
| 19 | + // output.appendMarkdown( proc.description.des) |
| 20 | + // output.appendCodeblock("assembly", proc.description.paramsString()) |
| 21 | + // output.appendCodeblock("assembly", proc.description.outputs()) |
| 22 | + // }else if(macro !== undefined) { |
| 23 | + // if(macro.short){ |
| 24 | + // output.appendCodeblock("assembly","(Macro) " + macro.name + " => " + macro.des.des) |
| 25 | + // }else{ |
| 26 | + // output.appendCodeblock("assembly","(Macro) " + macro.name) |
| 27 | + // output.appendText(macro.des.des) |
| 28 | + // output.appendCodeblock("assembly",macro.des.paramsStringMac()) |
| 29 | + // output.appendCodeblock("assembly",macro.des.outputs() ) |
| 30 | + // } |
| 31 | + // } |
| 32 | + else if(keyword !== undefined){ |
| 33 | + let md=info.getType(keyword.type)+" **"+keyword.name+"**\n\n"+keyword.def |
| 34 | + output.appendMarkdown(md) |
| 35 | + output.appendCodeblock("Syntax: " + keyword.data) |
| 36 | + } |
| 37 | + //else if(label !== undefined){ |
| 38 | + // output.appendCodeblock('assembly','(Label) ' + label.name + " => " + label.value) |
| 39 | + // } |
| 40 | + } |
| 41 | + return new vscode.Hover(output);} |
| 42 | +} |
| 43 | + |
| 44 | +export function hoveractivate(context: vscode.ExtensionContext) { |
| 45 | + if(vscode.workspace.getConfiguration('masmtasm.language').get('hover'))context.subscriptions.push(vscode.languages.registerHoverProvider('assembly',new TasmHoverProvider())); |
| 46 | +} |
| 47 | + |
0 commit comments