robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1" Vim completion script 2" Language: Java Script 3" Maintainer: Jay Sitter (jay@jaysitter.com) 4" URL: https://github.com/vim-language-dept/javascript-complete.vim/ 5" Previous Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl ) 6" Last Change: 2020 Jul 30 7" 2026 Sep 28 by Vim project: fix syntax error #21388 8 9function ! javascriptcomplete#CompleteJS ( findstart , base ) 10if a: findstart 11" locate the start of the word 12let line = getline ( '.' ) 13let start = col ( '.' ) - 1 14let curline = line ( '.' ) 15let compl_begin = col ( '.' ) - 2 16" Bit risky but JS is rather limited language and local chars shouldn't 17" fint way into names 18while start >= 0 && line [ start - 1 ] =~ '\k' 19let start -= 1 20endwhile 21let b: compl_context = getline ( '.' )[ 0 : compl_begin ] 22return start 23else 24" Initialize base return lists 25let res = [] 26let res2 = [] 27" a:base is very short - we need context 28" Shortcontext is context without a:base, useful for checking if we are 29" looking for objects and for what objects we are looking for 30let context = b: compl_context 31let shortcontext = substitute ( context , a: base . '$' , '' , '' ) 32unlet ! b: compl_context 33 34if exists ( "b:jsrange" ) 35let file = getline ( b: jsrange [ 0 ], b: jsrange [ 1 ]) 36unlet ! b: jsrange 37 38if len ( b: js_extfiles ) > 0 39let file = b: js_extfiles + file 40endif 41 42else 43let file = getline ( 1 , '$' ) 44endif 45 46 47" Completion of properties, methods, etc. {{{ 48if shortcontext =~ '\.$' 49" Complete methods and properties for objects 50" DOM separate 51let doms = [ 'style.' ] 52" Arrays 53let arrayprop = [ 'constructor' , 'index' , 'input' , 'length' , 'prototype' ] 54let arraymeth = [ 'concat' , 'join' , 'pop' , 'push' , 'reverse' , 'shift' , 55 \'splice' , 'sort' , 'toSource' , 'toString' , 'unshift' , 'valueOf' , 56 \'watch' , 'unwatch' ] 57call map ( arraymeth , 'v:val."("' ) 58let arrays = arrayprop + arraymeth 59 60" Boolean - complete subset of array values 61" properties - constructor, prototype 62" methods - toSource, toString, valueOf 63 64" Date 65" properties - constructor, prototype 66let datemeth = [ 'getDate' , 'getDay' , 'getFullYear' , 'getHours' , 'getMilliseconds' , 67 \'getMinutes' , 'getMonth' , 'getSeconds' , 'getTime' , 'getTimezoneOffset' , 68 \'getUTCDate' , 'getUTCDay' , 'getUTCFullYear' , 'getUTCHours' , 'getUTCMilliseconds' , 69 \'getUTCMinutes' , 'getUTCMonth' , 'getUTCSeconds' , 70 \'getYear' , 'parse' , 'parse' , 71 \'setDate' , 'setDay' , 'setFullYear' , 'setHours' , 'setMilliseconds' , 72 \'setMinutes' , 'setMonth' , 'setSeconds' , 73 \'setUTCDate' , 'setUTCDay' , 'setUTCFullYear' , 'setUTCHours' , 'setUTCMilliseconds' , 74 \'setUTCMinutes' , 'setUTCMonth' , 'setUTCSeconds' , 'setYear' , 'setTime' , 75 \'toGMTString' , 'toLocaleString' , 'toLocaleDateString' , 'toLocaleTimeString' , 76 \'toSource' , 'toString' , 'toUTCString' , 'UTC' , 'valueOf' , 'watch' , 'unwatch' ] 77call map ( datemeth , 'v:val."("' ) 78let dates = datemeth 79 80" Function 81let funcprop = [ 'arguments' , 'arguments.callee' , 'arguments.caller' , 'arguments.length' , 82 \'arity' , 'constructor' , 'length' , 'prototype' ] 83let funcmeth = [ 'apply' , 'call' , 'toSource' , 'toString' , 'valueOf' ] 84call map ( funcmeth , 'v:val."("' ) 85let funcs = funcprop + funcmeth 86 87" Math 88let mathprop = [ 'E' , 'LN2' , 'LN10' , 'LOG2E' , 'LOG10E' , 'PI' , 'SQRT1_2' , 'SQRT' ] 89let mathmeth = [ 'abs' , 'acos' , 'asin' , 'atan' , 'atan2' , 'ceil' , 'cos' , 'exp' , 'floor' , 90 \'log' , 'max' , 'min' , 'pow' , 'random' , 'round' , 'sin' , 'sqrt' , 'tan' , 91 \'watch' , 'unwatch' ] 92call map ( mathmeth , 'v:val."("' ) 93let maths = mathprop + mathmeth 94 95" Number 96let numbprop = [ 'MAX_VALUE' , 'MIN_VALUE' , 'NaN' , 'NEGATIVE_INFINITY' , 'POSITIVE_INFINITY' , 97 \'constructor' , 'prototype' ] 98let numbmeth = [ 'toExponential' , 'toFixed' , 'toPrecision' , 'toSource' , 'toString' , 'valueOf' , 99 \'watch' , 'unwatch' ] 100call map ( numbmeth , 'v:val."("' ) 101let numbs = numbprop + numbmeth 102 103" Object 104let objeprop = [ 'constructor' , 'prototype' ] 105let objemeth = [ 'eval' , 'toSource' , 'toString' , 'unwatch' , 'watch' , 'valueOf' ] 106call map ( objemeth , 'v:val."("' ) 107let objes = objeprop + objemeth 108 109" RegExp 110let regeprop = [ 'constructor' , 'global' , 'ignoreCase' , 'lastIndex' , 'multiline' , 'source' , 'prototype' ] 111let regemeth = [ 'exec' , 'test' , 'toSource' , 'toString' , 'watch' , 'unwatch' ] 112call map ( regemeth , 'v:val."("' ) 113let reges = regeprop + regemeth 114 115" String 116let striprop = [ 'constructor' , 'length' , 'prototype' ] 117let strimeth = [ 'anchor' , 'big' , 'blink' , 'bold' , 'charAt' , 'charCodeAt' , 'concat' , 118 \'fixed' , 'fontcolor' , 'fontsize' , 'fromCharCode' , 'indexOf' , 'italics' , 119 \'lastIndexOf' , 'link' , 'match' , 'replace' , 'search' , 'slice' , 'small' , 120 \'split' , 'strike' , 'sub' , 'substr' , 'substring' , 'sup' , 'toLowerCase' , 121 \'toSource' , 'toString' , 'toUpperCase' , 'watch' , 'unwatch' ] 122call map ( strimeth , 'v:val."("' ) 123let stris = striprop + strimeth 124 125" User created properties 126let user_props1 = filter ( copy ( file ), 'v:val =~ "this\\.\\k"' ) 127let juser_props1 = join ( user_props1 , ' ' ) 128let user_props1 = split ( juser_props1 , '\zethis\.' ) 129unlet ! juser_props1 130call map ( user_props1 , 'matchstr(v:val, "this\\.\\zs\\k\\+\\ze")' ) 131 132let user_props2 = filter ( copy ( file ), 'v:val =~ "\\.prototype\\.\\k"' ) 133let juser_props2 = join ( user_props2 , ' ' ) 134let user_props2 = split ( juser_props2 , '\zeprototype\.' ) 135unlet ! juser_props2 136call map ( user_props2 , 'matchstr(v:val, "prototype\\.\\zs\\k\\+\\ze")' ) 137let user_props = user_props1 + user_props2 138 139" HTML DOM properties 140" Anchors - anchor. 141let anchprop = [ 'accessKey' , 'charset' , 'coords' , 'href' , 'hreflang' , 'id' , 'innerHTML' , 142 \'name' , 'rel' , 'rev' , 'shape' , 'tabIndex' , 'target' , 'type' , 'onBlur' , 'onFocus' ] 143let anchmeth = [ 'blur' , 'focus' ] 144call map ( anchmeth , 'v:val."("' ) 145let anths = anchprop + anchmeth 146" Area - area. 147let areaprop = [ 'accessKey' , 'alt' , 'coords' , 'hash' , 'host' , 'hostname' , 'href' , 'id' , 148 \'noHref' , 'pathname' , 'port' , 'protocol' , 'search' , 'shape' , 'tabIndex' , 'target' ] 149let areameth = [ 'onClick' , 'onDblClick' , 'onMouseOut' , 'onMouseOver' ] 150call map ( areameth , 'v:val."("' ) 151let areas = areaprop + areameth 152" Base - base. 153let baseprop = [ 'href' , 'id' , 'target' ] 154let bases = baseprop 155" Body - body. 156let bodyprop = [ 'aLink' , 'background' , 'gbColor' , 'id' , 'link' , 'scrollLeft' , 'scrollTop' , 157 \'text' , 'vLink' ] 158let bodys = bodyprop 159" Document - document. 160let docuprop = [ 'anchors' , 'applets' , 'body' , 'characterSet' , 'childNodes' , 161 \'doctype' , 'documentElement' , 'documentURI' , 'embeds' , 'fonts' , 'forms' , 162 \'head' , 'hidden' , 'images' , 'implementation' , 'lastStyleSheetSet' , 163 \'links' , 'plugins' , 'preferredStyleSheetSet' , 'scripts' , 164 \'scrollingElement' , 'selectedStyleSheetSet' , 'styleSheetSets' , 165 \'timeline' , 'visibilityState' , 'cookie' , 'defaultView' , 166 \'designMode' , 'dir' , 'domain' , 'lastModified' , 'location' , 167 \'readyState' , 'referrer' , 'title' , 'URL' , 'activeElement' , 168 \'fullscreenElement' , 'styleSheets' ] 169let documeth = [ 'adoptNode' , 'close' , 'createAttribute' , 170 \'createAttributeNS' , 'createCDATASection' , 'createComment' , 171 \'createDocumentFragment' , 'createElement' , 'createElementNS' , 172 \'createEvent' , 'createExpression' , 'createNSResolver' , 173 \'createNodeIterator' , 'createProcessingInstruction' , 'createRange' , 174 \'createTextNode' , 'createTouchList' , 'createTreeWalker' , 175 \'enableStyleSheetsForSet' , 'evaluate' , 'focus' , 176 \'getElementById' , 'getElementsByClassName' , 'getElementsByName' , 177 \'getElementsByTagName' , 'getElementsByTagNameNS' , 178 \'hasStorageAccess' , 'importNode' , 'onClick' , 'onDblClick' , 179 \'onFocus' , 'onKeyDown' , 'onKeyPress' , 'onKeyUp' , 'onMouseDown' , 180 \'onMouseMove' , 'onMouseOut' , 'onMouseOver' , 'onMouseUp' , 181 \'onResize' , 'open' , 'querySelector' , 'querySelectorAll' , 182 \'requestStorageAccess' , 'write' , 'writeln' ] 183 184call map ( documeth , 'v:val."("' ) 185let docuxprop = [ 'attributes' , 'childNodes' , 'doctype' , 'documentElement' , 'firstChild' , 186 \'implementation' , 'namespaceURI' , 'nextSibling' , 'nodeName' , 'nodeType' , 187 \'nodeValue' , 'ownerDocument' , 'parentNode' , 'previousSibling' ] 188let docuxmeth = [ 'createAttribute' , 'createCDATASection' , 189 \'createComment' , 'createDocument' , 'createDocumentFragment' , 190 \'createElement' , 'createEntityReference' , 'createProcessingInstruction' , 191 \'createTextNode' ] 192call map ( docuxmeth , 'v:val."("' ) 193let docus = docuprop + docuxprop + documeth + docuxmeth 194" Form - form. 195let formprop = [ 'elements' , 'acceptCharset' , 'action' , 'encoding' , 'enctype' , 'id' , 'length' , 196 \'method' , 'name' , 'tabIndex' , 'target' ] 197let formmeth = [ 'reset' , 'submit' , 'onReset' , 'onSubmit' ] 198call map ( formmeth , 'v:val."("' ) 199let forms = formprop + formmeth 200" Frame - frame. 201let framprop = [ 'contentDocument' , 'frameBorder' , 'id' , 'longDesc' , 'marginHeight' , 'marginWidth' , 202 \'name' , 'noResize' , 'scrolling' , 'src' ] 203let frammeth = [ 'blur' , 'focus' ] 204call map ( frammeth , 'v:val."("' ) 205let frams = framprop + frammeth 206" Frameset - frameset. 207let fsetprop = [ 'cols' , 'id' , 'rows' ] 208let fsetmeth = [ 'blur' , 'focus' ] 209call map ( fsetmeth , 'v:val."("' ) 210let fsets = fsetprop + fsetmeth 211" History - history. 212let histprop = [ 'length' ] 213let histmeth = [ 'back' , 'forward' , 'go' ] 214call map ( histmeth , 'v:val."("' ) 215let hists = histprop + histmeth 216" Iframe - iframe. 217let ifraprop = [ 'align' , 'frameBorder' , 'height' , 'id' , 'longDesc' , 'marginHeight' , 'marginWidth' , 218 \'name' , 'scrolling' , 'src' , 'width' ] 219let ifras = ifraprop 220" Image - image. 221let imagprop = [ 'align' , 'alt' , 'border' , 'complete' , 'height' , 'hspace' , 'id' , 'isMap' , 'longDesc' , 222 \'lowSrc' , 'name' , 'src' , 'useMap' , 'vspace' , 'width' ] 223let imagmeth = [ 'onAbort' , 'onError' , 'onLoad' ] 224call map ( imagmeth , 'v:val."("' ) 225let imags = histprop + imagmeth 226" Button - accessible only by other properties 227let buttprop = [ 'accessKey' , 'disabled' , 'form' , 'id' , 'name' , 'tabIndex' , 'type' , 'value' ] 228let buttmeth = [ 'blur' , 'click' , 'focus' , 'onBlur' , 'onClick' , 'onFocus' , 'onMouseDown' , 'onMouseUp' ] 229call map ( buttmeth , 'v:val."("' ) 230let butts = buttprop + buttmeth 231" Checkbox - accessible only by other properties 232let checprop = [ 'accept' , 'accessKey' , 'align' , 'alt' , 'checked' , 'defaultChecked' , 233 \'disabled' , 'form' , 'id' , 'name' , 'tabIndex' , 'type' , 'value' ] 234let checmeth = [ 'blur' , 'click' , 'focus' , 'onBlur' , 'onClick' , 'onFocus' , 'onMouseDown' , 'onMouseUp' ] 235call map ( checmeth , 'v:val."("' ) 236let checs = checprop + checmeth 237" File upload - accessible only by other properties 238let fileprop = [ 'accept' , 'accessKey' , 'align' , 'alt' , 'defaultValue' , 239 \'disabled' , 'form' , 'id' , 'name' , 'tabIndex' , 'type' , 'value' ] 240let filemeth = [ 'blur' , 'focus' , 'onBlur' , 'onClick' , 'onFocus' , 'onMouseDown' , 'onMouseUp' ] 241call map ( filemeth , 'v:val."("' ) 242let files = fileprop + filemeth 243" Hidden - accessible only by other properties 244let hiddprop = [ 'defaultValue' , 'form' , 'id' , 'name' , 'type' , 'value' ] 245let hidds = hiddprop 246" Password - accessible only by other properties 247let passprop = [ 'accept' , 'accessKey' , 'defaultValue' , 248 \'disabled' , 'form' , 'id' , 'maxLength' , 'name' , 'readOnly' , 'size' , 'tabIndex' , 249 \'type' , 'value' ] 250let passmeth = [ 'blur' , 'click' , 'focus' , 'select' , 'onBlur' , 'onFocus' , 'onKeyDown' , 251 \'onKeyPress' , 'onKeyUp' ] 252call map ( passmeth , 'v:val."("' ) 253let passs = passprop + passmeth 254" Radio - accessible only by other properties 255let radiprop = [ 'accept' , 'accessKey' , 'align' , 'alt' , 'checked' , 'defaultChecked' , 256 \'disabled' , 'form' , 'id' , 'name' , 'tabIndex' , 'type' , 'value' ] 257let radimeth = [ 'blur' , 'click' , 'focus' , 'select' , 'onBlur' , 'onFocus' ] 258call map ( radimeth , 'v:val."("' ) 259let radis = radiprop + radimeth 260" Reset - accessible only by other properties 261let reseprop = [ 'accept' , 'accessKey' , 'align' , 'alt' , 'defaultValue' , 262 \'disabled' , 'form' , 'id' , 'name' , 'size' , 'tabIndex' , 'type' , 'value' ] 263let resemeth = [ 'blur' , 'click' , 'focus' , 'select' , 'onBlur' , 'onFocus' ] 264call map ( resemeth , 'v:val."("' ) 265let reses = reseprop + resemeth 266" Submit - accessible only by other properties 267let submprop = [ 'accept' , 'accessKey' , 'align' , 'alt' , 'defaultValue' , 268 \'disabled' , 'form' , 'id' , 'name' , 'size' , 'tabIndex' , 'type' , 'value' ] 269let submmeth = [ 'blur' , 'click' , 'focus' , 'select' , 'onClick' , 'onSelectStart' ] 270call map ( submmeth , 'v:val."("' ) 271let subms = submprop + submmeth 272" Text - accessible only by other properties 273let textprop = [ 'accept' , 'accessKey' , 'align' , 'alt' , 'defaultValue' , 274 \'disabled' , 'form' , 'id' , 'maxLength' , 'name' , 'readOnly' , 275 \'size' , 'tabIndex' , 'type' , 'value' ] 276let textmeth = [ 'blur' , 'focus' , 'select' , 'onBlur' , 'onChange' , 'onFocus' , 'onKeyDown' , 277 \'onKeyPress' , 'onKeyUp' , 'onSelect' ] 278call map ( textmeth , 'v:val."("' ) 279let texts = textprop + textmeth 280" Link - link. 281let linkprop = [ 'charset' , 'disabled' , 'href' , 'hreflang' , 'id' , 'media' , 282 \'rel' , 'rev' , 'target' , 'type' ] 283let linkmeth = [ 'onLoad' ] 284call map ( linkmeth , 'v:val."("' ) 285let links = linkprop + linkmeth 286" Location - location. 287let locaprop = [ 'href' , 'hash' , 'host' , 'hostname' , 'pathname' , 'port' , 'protocol' , 288 \'search' ] 289let locameth = [ 'assign' , 'reload' , 'replace' ] 290call map ( locameth , 'v:val."("' ) 291let locas = locaprop + locameth 292" Meta - meta. 293let metaprop = [ 'charset' , 'content' , 'disabled' , 'httpEquiv' , 'name' , 'scheme' ] 294let metas = metaprop 295" Navigator - navigator. 296let naviprop = [ 'plugins' , 'appCodeName' , 'appName' , 'appVersion' , 'cookieEnabled' , 297 \'platform' , 'userAgent' ] 298let navimeth = [ 'javaEnabled' , 'taintEnabled' ] 299call map ( navimeth , 'v:val."("' ) 300let navis = naviprop + navimeth 301" Object - object. 302let objeprop = [ 'align' , 'archive' , 'border' , 'code' , 'codeBase' , 'codeType' , 'data' , 303 \'declare' , 'form' , 'height' , 'hspace' , 'id' , 'name' , 'standby' , 'tabIndex' , 304 \'type' , 'useMap' , 'vspace' , 'width' ] 305let objes = objeprop 306" Option - accessible only by other properties 307let optiprop = [ 'defaultSelected' , 308 \'disabled' , 'form' , 'id' , 'index' , 'label' , 'selected' , 'text' , 'value' ] 309let optis = optiprop 310" Screen - screen. 311let screprop = [ 'availHeight' , 'availWidth' , 'colorDepth' , 'height' , 'width' ] 312let scres = screprop 313" Select - accessible only by other properties 314let seleprop = [ 'options' , 'disabled' , 'form' , 'id' , 'length' , 'multiple' , 'name' , 315 \'selectedIndex' , 'size' , 'tabIndex' , 'type' , 'value' ] 316let selemeth = [ 'blur' , 'focus' , 'remove' , 'onBlur' , 'onChange' , 'onFocus' ] 317call map ( selemeth , 'v:val."("' ) 318let seles = seleprop + selemeth 319" Style - style. 320let stylprop = [ 'background' , 'backgroundAttachment' , 'backgroundColor' , 'backgroundImage' , 321 \'backgroundPosition' , 'backgroundRepeat' , 322 \'border' , 'borderBottom' , 'borderLeft' , 'borderRight' , 'borderTop' , 323 \'borderBottomColor' , 'borderLeftColor' , 'borderRightColor' , 'borderTopColor' , 324 \'borderBottomStyle' , 'borderLeftStyle' , 'borderRightStyle' , 'borderTopStyle' , 325 \'borderBottomWidth' , 'borderLeftWidth' , 'borderRightWidth' , 'borderTopWidth' , 326 \'borderColor' , 'borderStyle' , 'borderWidth' , 'margin' , 'marginBottom' , 327 \'marginLeft' , 'marginRight' , 'marginTop' , 'outline' , 'outlineStyle' , 'outlineWidth' , 328 \'outlineColor' , 'outlineStyle' , 'outlineWidth' , 'padding' , 'paddingBottom' , 329 \'paddingLeft' , 'paddingRight' , 'paddingTop' , 330 \'clear' , 'clip' , 'clipBottom' , 'clipLeft' , 'clipRight' , 'clipTop' , 'content' , 331 \'counterIncrement' , 'counterReset' , 'cssFloat' , 'cursor' , 'direction' , 332 \'display' , 'markerOffset' , 'marks' , 'maxHeight' , 'maxWidth' , 'minHeight' , 333 \'minWidth' , 'overflow' , 'overflowX' , 'overflowY' , 'verticalAlign' , 'visibility' , 334 \'width' , 335 \'listStyle' , 'listStyleImage' , 'listStylePosition' , 'listStyleType' , 336 \'cssText' , 'bottom' , 'height' , 'left' , 'position' , 'right' , 'top' , 'width' , 'zindex' , 337 \'orphans' , 'widows' , 'page' , 'pageBreakAfter' , 'pageBreakBefore' , 'pageBreakInside' , 338 \'borderCollapse' , 'borderSpacing' , 'captionSide' , 'emptyCells' , 'tableLayout' , 339 \'color' , 'font' , 'fontFamily' , 'fontSize' , 'fontSizeAdjust' , 'fontStretch' , 340 \'fontStyle' , 'fontVariant' , 'fontWeight' , 'letterSpacing' , 'lineHeight' , 'quotes' , 341 \'textAlign' , 'textIndent' , 'textShadow' , 'textTransform' , 'textUnderlinePosition' , 342 \'unicodeBidi' , 'whiteSpace' , 'wordSpacing' ] 343let styls = stylprop 344" Table - table. 345let tablprop = [ 'rows' , 'tBodies' , 'align' , 'bgColor' , 'border' , 'caption' , 'cellPadding' , 346 \'cellSpacing' , 'frame' , 'height' , 'rules' , 'summary' , 'tFoot' , 'tHead' , 'width' ] 347let tablmeth = [ 'createCaption' , 'createTFoot' , 'createTHead' , 'deleteCaption' , 'deleteRow' , 348 \'deleteTFoot' , 'deleteTHead' , 'insertRow' ] 349call map ( tablmeth , 'v:val."("' ) 350let tabls = tablprop + tablmeth 351" Table data - TableData. 352let tdatprop = [ 'abbr' , 'align' , 'axis' , 'bgColor' , 'cellIndex' , 'ch' , 'chOff' , 353 \'colSpan' , 'headers' , 'noWrap' , 'rowSpan' , 'scope' , 'vAlign' , 'width' ] 354let tdats = tdatprop 355" Table row - TableRow. 356let trowprop = [ 'cells' , 'align' , 'bgColor' , 'ch' , 'chOff' , 'rowIndex' , 'sectionRowIndex' , 357 \'vAlign' ] 358let trowmeth = [ 'deleteCell' , 'insertCell' ] 359call map ( trowmeth , 'v:val."("' ) 360let trows = trowprop + trowmeth 361" Textarea - accessible only by other properties 362let tareprop = [ 'accessKey' , 'cols' , 'defaultValue' , 363 \'disabled' , 'form' , 'id' , 'name' , 'readOnly' , 'rows' , 364 \'tabIndex' , 'type' , 'value' , 'selectionStart' , 'selectionEnd' ] 365let taremeth = [ 'blur' , 'focus' , 'select' , 'onBlur' , 'onChange' , 'onFocus' ] 366call map ( taremeth , 'v:val."("' ) 367let tares = tareprop + taremeth 368" Window - window. 369let windprop = [ 'frames' , 'closed' , 'defaultStatus' , 'encodeURI' , 'event' , 'history' , 370 \'length' , 'location' , 'name' , 'onload' , 'opener' , 'parent' , 'screen' , 'self' , 371 \'status' , 'top' , 'XMLHttpRequest' , 'ActiveXObject' ] 372let windmeth = [ 'alert' , 'blur' , 'clearInterval' , 'clearTimeout' , 'close' , 'confirm' , 'focus' , 373 \'moveBy' , 'moveTo' , 'open' , 'print' , 'prompt' , 'scrollBy' , 'scrollTo' , 'setInterval' , 374 \'setTimeout' ] 375call map ( windmeth , 'v:val."("' ) 376let winds = windprop + windmeth 377" XMLHttpRequest - access by new xxx() 378let xmlhprop = [ 'onreadystatechange' , 'readyState' , 'responseText' , 'responseXML' , 379 \'status' , 'statusText' , 'parseError' ] 380let xmlhmeth = [ 'abort' , 'getAllResponseHeaders' , 'getResponseHeaders' , 'open' , 381 \'send' , 'setRequestHeader' ] 382call map ( xmlhmeth , 'v:val."("' ) 383let xmlhs = xmlhprop + xmlhmeth 384 385" XML DOM 386" Attributes - element.attributes[x]. 387let xdomattrprop = [ 'name' , 'specified' , 'value' ] 388" Element - anyelement. 389let xdomelemprop = [ 'attributes' , 'childNodes' , 'firstChild' , 'lastChild' , 390 \'namespaceURI' , 'nextSibling' , 'nodeName' , 'nodeType' , 'nodeValue' , 391 \'ownerDocument' , 'parentNode' , 'prefix' , 'previousSibling' , 'tagName' ] 392let xdomelemmeth = [ 'appendChild' , 'addEventListener' , 'cloneNode' , 393 \'dispatchEvent' , 'getAttribute' , 'getAttributeNode' , 394 \'getElementsByTagName' , 'hasChildNodes' , 'insertBefore' , 395 \'normalize' , 'removeAttribute' , 'removeAttributeNode' , 396 \'removeChild' , 'removeEventListener' , 'replaceChild' , 397 \'setAttribute' , 'setAttributeNode' ] 398call map ( xdomelemmeth , 'v:val."("' ) 399let xdomelems = xdomelemprop + xdomelemmeth 400" Node - anynode. 401let xdomnodeprop = [ 'attributes' , 'childNodes' , 'firstChild' , 'lastChild' , 402 \'namespaceURI' , 'nextSibling' , 'nodeName' , 'nodeType' , 'nodeValue' , 403 \'ownerDocument' , 'parentNode' , 'prefix' , 'previousSibling' ] 404let xdomnodemeth = [ 'appendChild' , 'cloneNode' , 405 \'hasChildNodes' , 'insertBefore' , 'removeChild' , 'replaceChild' ] 406call map ( xdomnodemeth , 'v:val."("' ) 407let xdomnodes = xdomnodeprop + xdomnodemeth 408" NodeList 409let xdomnliss = [ 'length' , 'item(' ] 410" Error - parseError. 411let xdomerror = [ 'errorCode' , 'reason' , 'line' , 'linepos' , 'srcText' , 'url' , 'filepos' ] 412 413" Find object type declaration to reduce number of suggestions. {{{ 414" 1. Get object name 415" 2. Find object declaration line 416" 3. General declaration follows "= new Type" syntax, additional else 417" for regexp "= /re/" 418" 4. Make correction for Microsoft.XMLHTTP ActiveXObject 419" 5. Repeat for external files 420let object = matchstr ( shortcontext , '\zs\k\+\ze\(\[.\{-}\]\)\?\.$' ) 421if len ( object ) > 0 422let decl_line = search ( object . '.\{-}=\s*new\s*' , 'bn' ) 423if decl_line > 0 424let object_type = matchstr ( getline ( decl_line ), object . '.\{-}=\s*new\s*\zs\k\+\ze' ) 425if object_type == 'ActiveXObject' && matchstr ( getline ( decl_line ), object . '.\{-}=\s*new\s*ActiveXObject\s*(.Microsoft\.XMLHTTP.)' ) != '' 426let object_type = 'XMLHttpRequest' 427endif 428else 429let decl_line = search ( 'var\s*' . object . '\s*=\s*\/' , 'bn' ) 430if decl_line > 0 431let object_type = 'RegExp' 432endif 433endif 434" We didn't find var declaration in current file but we may have 435" something in external files. 436if decl_line == 0 && exists ( "b:js_extfiles" ) 437let dext_line = filter ( copy ( b: js_extfiles ), 'v:val =~ "' . object . '.\\{-}=\\s*new\\s*"' ) 438if len ( dext_line ) > 0 439let object_type = matchstr ( dext_line [ -1 ], object . '.\{-}=\s*new\s*\zs\k\+\ze' ) 440if object_type == 'ActiveXObject' && matchstr ( dext_line [ -1 ], object . '.\{-}=\s*new\s*ActiveXObject\s*(.Microsoft\.XMLHTTP.)' ) != '' 441let object_type = 'XMLHttpRequest' 442endif 443else 444let dext_line = filter ( copy ( b: js_extfiles ), 'v:val =~ "var\s*' . object . '\\s*=\\s*\\/"' ) 445if len ( dext_line ) > 0 446let object_type = 'RegExp' 447endif 448endif 449endif 450endif 451" }}} 452 453if ! exists ( 'object_type' ) 454let object_type = '' 455endif 456 457if object_type == 'Date' 458let values = dates 459elseif object_type == 'Image' 460let values = imags 461elseif object_type == 'Array' 462let values = arrays 463elseif object_type == 'Boolean' 464" TODO: a bit more than real boolean 465let values = arrays 466elseif object_type == 'XMLHttpRequest' 467let values = xmlhs 468elseif object_type == 'String' 469let values = stris 470elseif object_type == 'RegExp' 471let values = reges 472elseif object_type == 'Math' 473let values = maths 474endif 475 476if ! exists ( 'values' ) 477" List of properties 478if shortcontext =~ 'Math\.$' 479let values = maths 480elseif shortcontext =~ 'anchors\(\[.\{-}\]\)\?\.$' 481let values = anths 482elseif shortcontext =~ 'area\.$' 483let values = areas 484elseif shortcontext =~ 'base\.$' 485let values = bases 486elseif shortcontext =~ 'body\.$' 487let values = bodys 488elseif shortcontext =~ 'document\.$' 489let values = docus 490elseif shortcontext =~ 'forms\(\[.\{-}\]\)\?\.$' 491let values = forms 492elseif shortcontext =~ 'frameset\.$' 493let values = fsets 494elseif shortcontext =~ 'history\.$' 495let values = hists 496elseif shortcontext =~ 'iframe\.$' 497let values = ifras 498elseif shortcontext =~ 'images\(\[.\{-}\]\)\?\.$' 499let values = imags 500elseif shortcontext =~ 'links\(\[.\{-}\]\)\?\.$' 501let values = links 502elseif shortcontext =~ 'location\.$' 503let values = locas 504elseif shortcontext =~ 'meta\.$' 505let values = metas 506elseif shortcontext =~ 'navigator\.$' 507let values = navis 508elseif shortcontext =~ 'object\.$' 509let values = objes 510elseif shortcontext =~ 'screen\.$' 511let values = scres 512elseif shortcontext =~ 'style\.$' 513let values = styls 514elseif shortcontext =~ 'table\.$' 515let values = tabls 516elseif shortcontext =~ 'TableData\.$' 517let values = tdats 518elseif shortcontext =~ 'TableRow\.$' 519let values = trows 520elseif shortcontext =~ 'window\.$' 521let values = winds 522elseif shortcontext =~ 'parseError\.$' 523let values = xdomerror 524elseif shortcontext =~ 'attributes\[\d\+\]\.$' 525let values = xdomattrprop 526else 527let values = user_props + arrays + dates + funcs + maths + numbs + objes + reges + stris 528let values += doms + anths + areas + bases + bodys + docus + forms + frams + fsets + hists 529let values += ifras + imags + links + locas + metas + navis + objes + scres 530let values += tabls + trows + tares + winds 531let values += xdomnodes + xdomnliss + xdomelems 532endif 533endif 534 535for m in values 536if m =~? '^' . a: base 537call add ( res , m ) 538elseif m =~? a: base 539call add ( res2 , m ) 540endif 541endfor 542 543unlet ! values 544return res + res2 545 546endif 547" }}} 548 549" Get variables data. 550let variables = filter ( copy ( file ), 'v:val =~ "var\\s"' ) 551call map ( variables , 'matchstr(v:val, ".\\{-}var\\s\\+\\zs.*\\ze")' ) 552call map ( variables , 'substitute(v:val, ";\\|$", ",", "g")' ) 553let vars = [] 554" This loop (and next one) is necessary to get variable names from 555" constructs like: var var1, var2, var3 = "something"; 556for i in range ( len ( variables )) 557let comma_separated = split ( variables [ i ], ',\s*' ) 558call map ( comma_separated , 'matchstr(v:val, "\\k\\+")' ) 559let vars += comma_separated 560endfor 561 562let variables = sort ( vars ) 563unlet ! vars 564 565" Add "no var" variables. 566let undeclared_variables = filter ( copy ( file ), 'v:val =~ "^\\s*\\k\\+\\s*="' ) 567let u_vars = [] 568for i in range ( len ( undeclared_variables )) 569let split_equal = split ( undeclared_variables [ i ], '\s*=' ) 570call map ( split_equal , 'matchstr(v:val, "\\k\\+$")' ) 571let u_vars += split_equal 572endfor 573 574let variables += sort ( u_vars ) 575unlet ! u_vars 576 577" Get functions 578let functions = filter ( copy ( file ), 'v:val =~ "^\\s*function\\s"' ) 579let arguments = copy ( functions ) 580call map ( functions , 'matchstr(v:val, "^\\s*function\\s\\+\\zs\\k\\+")' ) 581call map ( functions , 'v:val."("' ) 582let functions = sort ( functions ) 583 584" Create table to keep arguments for additional 'menu' info 585let b: js_menuinfo = {} 586for i in arguments 587let g: ia = i 588let f_elements = matchlist ( i , 'function\s\+\(\k\+\)\s*(\(.\{-}\))' ) 589if len ( f_elements ) >= 3 590let b: js_menuinfo [ f_elements [ 1 ] . '(' ] = f_elements [ 2 ] 591endif 592endfor 593 594" Get functions arguments 595call map ( arguments , 'matchstr(v:val, "function.\\{-}(\\zs.\\{-}\\ze)")' ) 596let jargs = join ( arguments , ',' ) 597let jargs = substitute ( jargs , '\s' , '' , 'g' ) 598let arguments = split ( jargs , ',' ) 599let arguments = sort ( arguments ) 600 601" Built-in functions 602let builtin = [ 'alert(' , 'confirm(' ] 603 604" Top-level HTML DOM objects 605let htmldom = [ 'document' , 'anchor' , 'area' , 'base' , 'body' , 'document' , 'event' , 'form' , 'frame' , 'frameset' , 'history' , 'iframe' , 'image' , 'input' , 'link' , 'location' , 'meta' , 'navigator' , 'object' , 'option' , 'screen' , 'select' , 'table' , 'tableData' , 'tableHeader' , 'tableRow' , 'textarea' , 'window' ] 606call map ( htmldom , 'v:val."."' ) 607 608" Top-level properties 609let properties = [ 'decodeURI' , 'decodeURIComponent' , 'encodeURI' , 'encodeURIComponent' , 610 \'eval' , 'Infinity' , 'isFinite' , 'isNaN' , 'NaN' , 'Number' , 'parseFloat' , 611 \'parseInt' , 'String' , 'undefined' , 'escape' , 'unescape' ] 612 613" Keywords 614let keywords = [ "Array" , "Boolean" , "Date" , "Function" , "Math" , "Number" , "Object" , "RegExp" , "String" , "XMLHttpRequest" , "ActiveXObject" , "abstract" , "boolean" , "break" , "byte" , "case" , "catch" , "char" , "class" , "const" , "continue" , "debugger" , "default" , "delete" , "do" , "double " , "else" , "enum" , "export" , "extends" , "false" , "final" , "finally" , "float" , "for" , "function" , "goto" , "if" , "implements" , "import" , "in " , "instanceof" , "int" , "interface" , "long" , "native" , "new" , "null" , "package" , "private" , "protected" , "public" , "return" , "short" , "static" , "super " , "switch" , "synchronized" , "this" , "throw" , "throws" , "transient" , "true" , "try" , "typeof" , "var" , "void" , "volatile" , "while" , "with" ] 615 616let values = variables + functions + htmldom + arguments + builtin + properties + keywords 617 618for m in values 619if m =~? '^' . a: base 620call add ( res , m ) 621elseif m =~? a: base 622call add ( res2 , m ) 623endif 624endfor 625 626let menu = res + res2 627let final_menu = [] 628for i in range ( len ( menu )) 629let item = menu [ i ] 630if item =~ '($' 631let kind = 'f' 632if has_key ( b: js_menuinfo , item ) 633let m_info = b: js_menuinfo [ item ] 634else 635let m_info = '' 636endif 637else 638let kind = 'v' 639let m_info = '' 640endif 641let final_menu += [{ 'word' : item , 'menu' : m_info , 'kind' : kind }] 642endfor 643let g: fm = final_menu 644return final_menu 645endif 646 647endfunction 648 649" vim:set foldmethod=marker: