import * as vscode from "vscode" ; let wlSymbolData = [ ] ; export function setWLSymbolData ( data ) { wlSymbolData = data . split ( "\n" ) . map ( line => { try { return JSON . parse ( line ) ; } catch ( err ) { console . log ( err , line ) ; return null ; } } ) . filter ( line => line !== null ) ; } ; const completionItemTypeTable = { "function" : vscode . CompletionItemKind . Function , "variable" : vscode . CompletionItemKind . Variable , "keyword" : vscode . CompletionItemKind . Keyword , "constant" : vscode . CompletionItemKind . Constant } ; export const wlCompletionProvider = { provideCompletionItems : function ( document , position , token , context ) { const defaultItems = [ ] as vscode . CompletionItem [ ] ; const prefixText = document . getText ( new vscode . Range ( position . line , 0 , position . line , position . character ) ) ; if ( token . isCancellationRequested ) { return defaultItems ; } const prefixWord = ( prefixText . match ( /[^$A-Z0-9]?([$A-Z][$A-Za-z0-9]*)$/ ) || [ "" , "" ] ) [ 1 ] ; const range = new vscode . Range ( position . line , position . character - prefixWord . length , position . line , position . character ) ; let items = [ ] ; wlSymbolData . forEach ( entry => { if ( token . isCancellationRequested ) { return defaultItems ; } let docString = new vscode . MarkdownString ( entry ?. usage || "" , false ) ; docString . supportHtml = true ; docString . isTrusted = true ; items . push ( { label : entry . name , kind : completionItemTypeTable [ entry . type ] || vscode . CompletionItemKind . Text , sortText : ( entry ?. rank || 99999 ) . toString ( ) . padStart ( 5 , "0" ) , documentation : docString , insertText : entry . name , range : range } ) ; } ) ; return items ; } } ; export const wlHoverProvider = { provideHover : function ( document , position , token ) { const wordRange = document . getWordRangeAtPosition ( position , /[$A-Za-z][$A-Za-z0-9]*/ ) ; const word = wordRange ? document . getText ( wordRange ) : "" ; if ( ! word ) { return null ; } const entry = wlSymbolData . find ( entry => entry . name === word ) ; if ( ! entry || ! entry ?. usage ) { return null ; } let hoverStrings = entry . usage . split ( "\\n\\n---\\n" ) ; if ( entry ?. url ) { hoverStrings . push ( `[Online Documentation »](${ entry . url })` ) ; } const hoverElement = new vscode . Hover ( hoverStrings . map ( str => { let md = new vscode . MarkdownString ( str ) ; md . isTrusted = true ; md . supportHtml = true ; return md ; } ) ) ; return hoverElement ; } } ;