javascriptcomplete.vim (28224B)
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 9 function! javascriptcomplete#CompleteJS(findstart, base) 10 if a:findstart 11 " locate the start of the word 12 let line = getline('.') 13 let start = col('.') - 1 14 let curline = line('.') 15 let compl_begin = col('.') - 2 16 " Bit risky but JS is rather limited language and local chars shouldn't 17 " fint way into names 18 while start >= 0 && line[start - 1] =~ '\k' 19 let start -= 1 20 endwhile 21 let b:compl_context = getline('.')[0:compl_begin] 22 return start 23 else 24 " Initialize base return lists 25 let res = [] 26 let 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 30 let context = b:compl_context 31 let shortcontext = substitute(context, a:base.'$', '', '') 32 unlet! b:compl_context 33 34 if exists("b:jsrange") 35 let file = getline(b:jsrange[0],b:jsrange[1]) 36 unlet! b:jsrange 37 38 if len(b:js_extfiles) > 0 39 let file = b:js_extfiles + file 40 endif 41 42 else 43 let file = getline(1, '$') 44 endif 45 46 47 " Completion of properties, methods, etc. {{{ 48 if shortcontext =~ '\.$' 49 " Complete methods and properties for objects 50 " DOM separate 51 let doms = ['style.'] 52 " Arrays 53 let arrayprop = ['constructor', 'index', 'input', 'length', 'prototype'] 54 let arraymeth = ['concat', 'join', 'pop', 'push', 'reverse', 'shift', 55 \ 'splice', 'sort', 'toSource', 'toString', 'unshift', 'valueOf', 56 \ 'watch', 'unwatch'] 57 call map(arraymeth, 'v:val."("') 58 let 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 66 let 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'] 77 call map(datemeth, 'v:val."("') 78 let dates = datemeth 79 80 " Function 81 let funcprop = ['arguments', 'arguments.callee', 'arguments.caller', 'arguments.length', 82 \ 'arity', 'constructor', 'length', 'prototype'] 83 let funcmeth = ['apply', 'call', 'toSource', 'toString', 'valueOf'] 84 call map(funcmeth, 'v:val."("') 85 let funcs = funcprop + funcmeth 86 87 " Math 88 let mathprop = ['E', 'LN2', 'LN10', 'LOG2E', 'LOG10E', 'PI', 'SQRT1_2', 'SQRT'] 89 let mathmeth = ['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 90 \ 'log', 'max', 'min', 'pow', 'random', 'round', 'sin', 'sqrt', 'tan', 91 \ 'watch', 'unwatch'] 92 call map(mathmeth, 'v:val."("') 93 let maths = mathprop + mathmeth 94 95 " Number 96 let numbprop = ['MAX_VALUE', 'MIN_VALUE', 'NaN', 'NEGATIVE_INFINITY', 'POSITIVE_INFINITY', 97 \ 'constructor', 'prototype'] 98 let numbmeth = ['toExponential', 'toFixed', 'toPrecision', 'toSource', 'toString', 'valueOf', 99 \ 'watch', 'unwatch'] 100 call map(numbmeth, 'v:val."("') 101 let numbs = numbprop + numbmeth 102 103 " Object 104 let objeprop = ['constructor', 'prototype'] 105 let objemeth = ['eval', 'toSource', 'toString', 'unwatch', 'watch', 'valueOf'] 106 call map(objemeth, 'v:val."("') 107 let objes = objeprop + objemeth 108 109 " RegExp 110 let regeprop = ['constructor', 'global', 'ignoreCase', 'lastIndex', 'multiline', 'source', 'prototype'] 111 let regemeth = ['exec', 'test', 'toSource', 'toString', 'watch', 'unwatch'] 112 call map(regemeth, 'v:val."("') 113 let reges = regeprop + regemeth 114 115 " String 116 let striprop = ['constructor', 'length', 'prototype'] 117 let 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'] 122 call map(strimeth, 'v:val."("') 123 let stris = striprop + strimeth 124 125 " User created properties 126 let user_props1 = filter(copy(file), 'v:val =~ "this\\.\\k"') 127 let juser_props1 = join(user_props1, ' ') 128 let user_props1 = split(juser_props1, '\zethis\.') 129 unlet! juser_props1 130 call map(user_props1, 'matchstr(v:val, "this\\.\\zs\\k\\+\\ze")') 131 132 let user_props2 = filter(copy(file), 'v:val =~ "\\.prototype\\.\\k"') 133 let juser_props2 = join(user_props2, ' ') 134 let user_props2 = split(juser_props2, '\zeprototype\.') 135 unlet! juser_props2 136 call map(user_props2, 'matchstr(v:val, "prototype\\.\\zs\\k\\+\\ze")') 137 let user_props = user_props1 + user_props2 138 139 " HTML DOM properties 140 " Anchors - anchor. 141 let anchprop = ['accessKey', 'charset', 'coords', 'href', 'hreflang', 'id', 'innerHTML', 142 \ 'name', 'rel', 'rev', 'shape', 'tabIndex', 'target', 'type', 'onBlur', 'onFocus'] 143 let anchmeth = ['blur', 'focus'] 144 call map(anchmeth, 'v:val."("') 145 let anths = anchprop + anchmeth 146 " Area - area. 147 let areaprop = ['accessKey', 'alt', 'coords', 'hash', 'host', 'hostname', 'href', 'id', 148 \ 'noHref', 'pathname', 'port', 'protocol', 'search', 'shape', 'tabIndex', 'target'] 149 let areameth = ['onClick', 'onDblClick', 'onMouseOut', 'onMouseOver'] 150 call map(areameth, 'v:val."("') 151 let areas = areaprop + areameth 152 " Base - base. 153 let baseprop = ['href', 'id', 'target'] 154 let bases = baseprop 155 " Body - body. 156 let bodyprop = ['aLink', 'background', 'gbColor', 'id', 'link', 'scrollLeft', 'scrollTop', 157 \ 'text', 'vLink'] 158 let bodys = bodyprop 159 " Document - document. 160 let 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'] 169 let 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 184 call map(documeth, 'v:val."("') 185 let docuxprop = ['attributes', 'childNodes', 'doctype', 'documentElement', 'firstChild', 186 \ 'implementation', 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType', 187 \ 'nodeValue', 'ownerDocument', 'parentNode', 'previousSibling'] 188 let docuxmeth = ['createAttribute', 'createCDATASection', 189 \ 'createComment', 'createDocument', 'createDocumentFragment', 190 \ 'createElement', 'createEntityReference', 'createProcessingInstruction', 191 \ 'createTextNode'] 192 call map(docuxmeth, 'v:val."("') 193 let docus = docuprop + docuxprop + documeth + docuxmeth 194 " Form - form. 195 let formprop = ['elements', 'acceptCharset', 'action', 'encoding', 'enctype', 'id', 'length', 196 \ 'method', 'name', 'tabIndex', 'target'] 197 let formmeth = ['reset', 'submit', 'onReset', 'onSubmit'] 198 call map(formmeth, 'v:val."("') 199 let forms = formprop + formmeth 200 " Frame - frame. 201 let framprop = ['contentDocument', 'frameBorder', 'id', 'longDesc', 'marginHeight', 'marginWidth', 202 \ 'name', 'noResize', 'scrolling', 'src'] 203 let frammeth = ['blur', 'focus'] 204 call map(frammeth, 'v:val."("') 205 let frams = framprop + frammeth 206 " Frameset - frameset. 207 let fsetprop = ['cols', 'id', 'rows'] 208 let fsetmeth = ['blur', 'focus'] 209 call map(fsetmeth, 'v:val."("') 210 let fsets = fsetprop + fsetmeth 211 " History - history. 212 let histprop = ['length'] 213 let histmeth = ['back', 'forward', 'go'] 214 call map(histmeth, 'v:val."("') 215 let hists = histprop + histmeth 216 " Iframe - iframe. 217 let ifraprop = ['align', 'frameBorder', 'height', 'id', 'longDesc', 'marginHeight', 'marginWidth', 218 \ 'name', 'scrolling', 'src', 'width'] 219 let ifras = ifraprop 220 " Image - image. 221 let imagprop = ['align', 'alt', 'border', 'complete', 'height', 'hspace', 'id', 'isMap', 'longDesc', 222 \ 'lowSrc', 'name', 'src', 'useMap', 'vspace', 'width'] 223 let imagmeth = ['onAbort', 'onError', 'onLoad'] 224 call map(imagmeth, 'v:val."("') 225 let imags = histprop + imagmeth 226 " Button - accessible only by other properties 227 let buttprop = ['accessKey', 'disabled', 'form', 'id', 'name', 'tabIndex', 'type', 'value'] 228 let buttmeth = ['blur', 'click', 'focus', 'onBlur', 'onClick', 'onFocus', 'onMouseDown', 'onMouseUp'] 229 call map(buttmeth, 'v:val."("') 230 let butts = buttprop + buttmeth 231 " Checkbox - accessible only by other properties 232 let checprop = ['accept', 'accessKey', 'align', 'alt', 'checked', 'defaultChecked', 233 \ 'disabled', 'form', 'id', 'name', 'tabIndex', 'type', 'value'] 234 let checmeth = ['blur', 'click', 'focus', 'onBlur', 'onClick', 'onFocus', 'onMouseDown', 'onMouseUp'] 235 call map(checmeth, 'v:val."("') 236 let checs = checprop + checmeth 237 " File upload - accessible only by other properties 238 let fileprop = ['accept', 'accessKey', 'align', 'alt', 'defaultValue', 239 \ 'disabled', 'form', 'id', 'name', 'tabIndex', 'type', 'value'] 240 let filemeth = ['blur', 'focus', 'onBlur', 'onClick', 'onFocus', 'onMouseDown', 'onMouseUp'] 241 call map(filemeth, 'v:val."("') 242 let files = fileprop + filemeth 243 " Hidden - accessible only by other properties 244 let hiddprop = ['defaultValue', 'form', 'id', 'name', 'type', 'value'] 245 let hidds = hiddprop 246 " Password - accessible only by other properties 247 let passprop = ['accept', 'accessKey', 'defaultValue', 248 \ 'disabled', 'form', 'id', 'maxLength', 'name', 'readOnly', 'size', 'tabIndex', 249 \ 'type', 'value'] 250 let passmeth = ['blur', 'click', 'focus', 'select', 'onBlur', 'onFocus', 'onKeyDown', 251 \ 'onKeyPress', 'onKeyUp'] 252 call map(passmeth, 'v:val."("') 253 let passs = passprop + passmeth 254 " Radio - accessible only by other properties 255 let radiprop = ['accept', 'accessKey', 'align', 'alt', 'checked', 'defaultChecked', 256 \ 'disabled', 'form', 'id', 'name', 'tabIndex', 'type', 'value'] 257 let radimeth = ['blur', 'click', 'focus', 'select', 'onBlur', 'onFocus'] 258 call map(radimeth, 'v:val."("') 259 let radis = radiprop + radimeth 260 " Reset - accessible only by other properties 261 let reseprop = ['accept', 'accessKey', 'align', 'alt', 'defaultValue', 262 \ 'disabled', 'form', 'id', 'name', 'size', 'tabIndex', 'type', 'value'] 263 let resemeth = ['blur', 'click', 'focus', 'select', 'onBlur', 'onFocus'] 264 call map(resemeth, 'v:val."("') 265 let reses = reseprop + resemeth 266 " Submit - accessible only by other properties 267 let submprop = ['accept', 'accessKey', 'align', 'alt', 'defaultValue', 268 \ 'disabled', 'form', 'id', 'name', 'size', 'tabIndex', 'type', 'value'] 269 let submmeth = ['blur', 'click', 'focus', 'select', 'onClick', 'onSelectStart'] 270 call map(submmeth, 'v:val."("') 271 let subms = submprop + submmeth 272 " Text - accessible only by other properties 273 let textprop = ['accept', 'accessKey', 'align', 'alt', 'defaultValue', 274 \ 'disabled', 'form', 'id', 'maxLength', 'name', 'readOnly', 275 \ 'size', 'tabIndex', 'type', 'value'] 276 let textmeth = ['blur', 'focus', 'select', 'onBlur', 'onChange', 'onFocus', 'onKeyDown', 277 \ 'onKeyPress', 'onKeyUp', 'onSelect'] 278 call map(textmeth, 'v:val."("') 279 let texts = textprop + textmeth 280 " Link - link. 281 let linkprop = ['charset', 'disabled', 'href', 'hreflang', 'id', 'media', 282 \ 'rel', 'rev', 'target', 'type'] 283 let linkmeth = ['onLoad'] 284 call map(linkmeth, 'v:val."("') 285 let links = linkprop + linkmeth 286 " Location - location. 287 let locaprop = ['href', 'hash', 'host', 'hostname', 'pathname', 'port', 'protocol', 288 \ 'search'] 289 let locameth = ['assign', 'reload', 'replace'] 290 call map(locameth, 'v:val."("') 291 let locas = locaprop + locameth 292 " Meta - meta. 293 let metaprop = ['charset', 'content', 'disabled', 'httpEquiv', 'name', 'scheme'] 294 let metas = metaprop 295 " Navigator - navigator. 296 let naviprop = ['plugins', 'appCodeName', 'appName', 'appVersion', 'cookieEnabled', 297 \ 'platform', 'userAgent'] 298 let navimeth = ['javaEnabled', 'taintEnabled'] 299 call map(navimeth, 'v:val."("') 300 let navis = naviprop + navimeth 301 " Object - object. 302 let objeprop = ['align', 'archive', 'border', 'code', 'codeBase', 'codeType', 'data', 303 \ 'declare', 'form', 'height', 'hspace', 'id', 'name', 'standby', 'tabIndex', 304 \ 'type', 'useMap', 'vspace', 'width'] 305 let objes = objeprop 306 " Option - accessible only by other properties 307 let optiprop = ['defaultSelected', 308 \ 'disabled', 'form', 'id', 'index', 'label', 'selected', 'text', 'value'] 309 let optis = optiprop 310 " Screen - screen. 311 let screprop = ['availHeight', 'availWidth', 'colorDepth', 'height', 'width'] 312 let scres = screprop 313 " Select - accessible only by other properties 314 let seleprop = ['options', 'disabled', 'form', 'id', 'length', 'multiple', 'name', 315 \ 'selectedIndex', 'size', 'tabIndex', 'type', 'value'] 316 let selemeth = ['blur', 'focus', 'remove', 'onBlur', 'onChange', 'onFocus'] 317 call map(selemeth, 'v:val."("') 318 let seles = seleprop + selemeth 319 " Style - style. 320 let 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'] 343 let styls = stylprop 344 " Table - table. 345 let tablprop = ['rows', 'tBodies', 'align', 'bgColor', 'border', 'caption', 'cellPadding', 346 \ 'cellSpacing', 'frame', 'height', 'rules', 'summary', 'tFoot', 'tHead', 'width'] 347 let tablmeth = ['createCaption', 'createTFoot', 'createTHead', 'deleteCaption', 'deleteRow', 348 \ 'deleteTFoot', 'deleteTHead', 'insertRow'] 349 call map(tablmeth, 'v:val."("') 350 let tabls = tablprop + tablmeth 351 " Table data - TableData. 352 let tdatprop = ['abbr', 'align', 'axis', 'bgColor', 'cellIndex', 'ch', 'chOff', 353 \ 'colSpan', 'headers', 'noWrap', 'rowSpan', 'scope', 'vAlign', 'width'] 354 let tdats = tdatprop 355 " Table row - TableRow. 356 let trowprop = ['cells', 'align', 'bgColor', 'ch', 'chOff', 'rowIndex', 'sectionRowIndex', 357 \ 'vAlign'] 358 let trowmeth = ['deleteCell', 'insertCell'] 359 call map(trowmeth, 'v:val."("') 360 let trows = trowprop + trowmeth 361 " Textarea - accessible only by other properties 362 let tareprop = ['accessKey', 'cols', 'defaultValue', 363 \ 'disabled', 'form', 'id', 'name', 'readOnly', 'rows', 364 \ 'tabIndex', 'type', 'value', 'selectionStart', 'selectionEnd'] 365 let taremeth = ['blur', 'focus', 'select', 'onBlur', 'onChange', 'onFocus'] 366 call map(taremeth, 'v:val."("') 367 let tares = tareprop + taremeth 368 " Window - window. 369 let windprop = ['frames', 'closed', 'defaultStatus', 'encodeURI', 'event', 'history', 370 \ 'length', 'location', 'name', 'onload', 'opener', 'parent', 'screen', 'self', 371 \ 'status', 'top', 'XMLHttpRequest', 'ActiveXObject'] 372 let windmeth = ['alert', 'blur', 'clearInterval', 'clearTimeout', 'close', 'confirm', 'focus', 373 \ 'moveBy', 'moveTo', 'open', 'print', 'prompt', 'scrollBy', 'scrollTo', 'setInterval', 374 \ 'setTimeout'] 375 call map(windmeth, 'v:val."("') 376 let winds = windprop + windmeth 377 " XMLHttpRequest - access by new xxx() 378 let xmlhprop = ['onreadystatechange', 'readyState', 'responseText', 'responseXML', 379 \ 'status', 'statusText', 'parseError'] 380 let xmlhmeth = ['abort', 'getAllResponseHeaders', 'getResponseHeaders', 'open', 381 \ 'send', 'setRequestHeader'] 382 call map(xmlhmeth, 'v:val."("') 383 let xmlhs = xmlhprop + xmlhmeth 384 385 " XML DOM 386 " Attributes - element.attributes[x]. 387 let xdomattrprop = ['name', 'specified', 'value'] 388 " Element - anyelement. 389 let xdomelemprop = ['attributes', 'childNodes', 'firstChild', 'lastChild', 390 \ 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType', 'nodeValue', 391 \ 'ownerDocument', 'parentNode', 'prefix', 'previousSibling', 'tagName'] 392 let xdomelemmeth = ['appendChild', 'addEventListener', 'cloneNode', 393 \ 'dispatchEvent', 'getAttribute', 'getAttributeNode', 394 \ 'getElementsByTagName', 'hasChildNodes', 'insertBefore', 395 \ 'normalize', 'removeAttribute', 'removeAttributeNode', 396 \ 'removeChild', 'removeEventListener', 'replaceChild', 397 \ 'setAttribute', 'setAttributeNode'] 398 call map(xdomelemmeth, 'v:val."("') 399 let xdomelems = xdomelemprop + xdomelemmeth 400 " Node - anynode. 401 let xdomnodeprop = ['attributes', 'childNodes', 'firstChild', 'lastChild', 402 \ 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType', 'nodeValue', 403 \ 'ownerDocument', 'parentNode', 'prefix', 'previousSibling'] 404 let xdomnodemeth = ['appendChild', 'cloneNode', 405 \ 'hasChildNodes', 'insertBefore', 'removeChild', 'replaceChild'] 406 call map(xdomnodemeth, 'v:val."("') 407 let xdomnodes = xdomnodeprop + xdomnodemeth 408 " NodeList 409 let xdomnliss = ['length', 'item('] 410 " Error - parseError. 411 let 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 420 let object = matchstr(shortcontext, '\zs\k\+\ze\(\[.\{-}\]\)\?\.$') 421 if len(object) > 0 422 let decl_line = search(object.'.\{-}=\s*new\s*', 'bn') 423 if decl_line > 0 424 let object_type = matchstr(getline(decl_line), object.'.\{-}=\s*new\s*\zs\k\+\ze') 425 if object_type == 'ActiveXObject' && matchstr(getline(decl_line), object.'.\{-}=\s*new\s*ActiveXObject\s*(.Microsoft\.XMLHTTP.)') != '' 426 let object_type = 'XMLHttpRequest' 427 endif 428 else 429 let decl_line = search('var\s*'.object.'\s*=\s*\/', 'bn') 430 if decl_line > 0 431 let object_type = 'RegExp' 432 endif 433 endif 434 " We didn't find var declaration in current file but we may have 435 " something in external files. 436 if decl_line == 0 && exists("b:js_extfiles") 437 let dext_line = filter(copy(b:js_extfiles), 'v:val =~ "'.object.'.\\{-}=\\s*new\\s*"') 438 if len(dext_line) > 0 439 let object_type = matchstr(dext_line[-1], object.'.\{-}=\s*new\s*\zs\k\+\ze') 440 if object_type == 'ActiveXObject' && matchstr(dext_line[-1], object.'.\{-}=\s*new\s*ActiveXObject\s*(.Microsoft\.XMLHTTP.)') != '' 441 let object_type = 'XMLHttpRequest' 442 endif 443 else 444 let dext_line = filter(copy(b:js_extfiles), 'v:val =~ "var\s*'.object.'\\s*=\\s*\\/"') 445 if len(dext_line) > 0 446 let object_type = 'RegExp' 447 endif 448 endif 449 endif 450 endif 451 " }}} 452 453 if !exists('object_type') 454 let object_type = '' 455 endif 456 457 if object_type == 'Date' 458 let values = dates 459 elseif object_type == 'Image' 460 let values = imags 461 elseif object_type == 'Array' 462 let values = arrays 463 elseif object_type == 'Boolean' 464 " TODO: a bit more than real boolean 465 let values = arrays 466 elseif object_type == 'XMLHttpRequest' 467 let values = xmlhs 468 elseif object_type == 'String' 469 let values = stris 470 elseif object_type == 'RegExp' 471 let values = reges 472 elseif object_type == 'Math' 473 let values = maths 474 endif 475 476 if !exists('values') 477 " List of properties 478 if shortcontext =~ 'Math\.$' 479 let values = maths 480 elseif shortcontext =~ 'anchors\(\[.\{-}\]\)\?\.$' 481 let values = anths 482 elseif shortcontext =~ 'area\.$' 483 let values = areas 484 elseif shortcontext =~ 'base\.$' 485 let values = bases 486 elseif shortcontext =~ 'body\.$' 487 let values = bodys 488 elseif shortcontext =~ 'document\.$' 489 let values = docus 490 elseif shortcontext =~ 'forms\(\[.\{-}\]\)\?\.$' 491 let values = forms 492 elseif shortcontext =~ 'frameset\.$' 493 let values = fsets 494 elseif shortcontext =~ 'history\.$' 495 let values = hists 496 elseif shortcontext =~ 'iframe\.$' 497 let values = ifras 498 elseif shortcontext =~ 'images\(\[.\{-}\]\)\?\.$' 499 let values = imags 500 elseif shortcontext =~ 'links\(\[.\{-}\]\)\?\.$' 501 let values = links 502 elseif shortcontext =~ 'location\.$' 503 let values = locas 504 elseif shortcontext =~ 'meta\.$' 505 let values = metas 506 elseif shortcontext =~ 'navigator\.$' 507 let values = navis 508 elseif shortcontext =~ 'object\.$' 509 let values = objes 510 elseif shortcontext =~ 'screen\.$' 511 let values = scres 512 elseif shortcontext =~ 'style\.$' 513 let values = styls 514 elseif shortcontext =~ 'table\.$' 515 let values = tabls 516 elseif shortcontext =~ 'TableData\.$' 517 let values = tdats 518 elseif shortcontext =~ 'TableRow\.$' 519 let values = trows 520 elseif shortcontext =~ 'window\.$' 521 let values = winds 522 elseif shortcontext =~ 'parseError\.$' 523 let values = xdomerror 524 elseif shortcontext =~ 'attributes\[\d\+\]\.$' 525 let values = xdomattrprop 526 else 527 let values = user_props + arrays + dates + funcs + maths + numbs + objes + reges + stris 528 let values += doms + anths + areas + bases + bodys + docus + forms + frams + fsets + hists 529 let values += ifras + imags + links + locas + metas + navis + objes + scres 530 let values += tabls + trows + tares + winds 531 let values += xdomnodes + xdomnliss + xdomelems 532 endif 533 endif 534 535 for m in values 536 if m =~? '^'.a:base 537 call add(res, m) 538 elseif m =~? a:base 539 call add(res2, m) 540 endif 541 endfor 542 543 unlet! values 544 return res + res2 545 546 endif 547 " }}} 548 549 " Get variables data. 550 let variables = filter(copy(file), 'v:val =~ "var\\s"') 551 call map(variables, 'matchstr(v:val, ".\\{-}var\\s\\+\\zs.*\\ze")') 552 call map(variables, 'substitute(v:val, ";\\|$", ",", "g")') 553 let vars = [] 554 " This loop (and next one) is necessary to get variable names from 555 " constructs like: var var1, var2, var3 = "something"; 556 for i in range(len(variables)) 557 let comma_separated = split(variables[i], ',\s*') 558 call map(comma_separated, 'matchstr(v:val, "\\k\\+")') 559 let vars += comma_separated 560 endfor 561 562 let variables = sort(vars) 563 unlet! vars 564 565 " Add "no var" variables. 566 let undeclared_variables = filter(copy(file), 'v:val =~ "^\\s*\\k\\+\\s*="') 567 let u_vars = [] 568 for i in range(len(undeclared_variables)) 569 let split_equal = split(undeclared_variables[i], '\s*=') 570 call map(split_equal, 'matchstr(v:val, "\\k\\+$")') 571 let u_vars += split_equal 572 endfor 573 574 let variables += sort(u_vars) 575 unlet! u_vars 576 577 " Get functions 578 let functions = filter(copy(file), 'v:val =~ "^\\s*function\\s"') 579 let arguments = copy(functions) 580 call map(functions, 'matchstr(v:val, "^\\s*function\\s\\+\\zs\\k\\+")') 581 call map(functions, 'v:val."("') 582 let functions = sort(functions) 583 584 " Create table to keep arguments for additional 'menu' info 585 let b:js_menuinfo = {} 586 for i in arguments 587 let g:ia = i 588 let f_elements = matchlist(i, 'function\s\+\(\k\+\)\s*(\(.\{-}\))') 589 if len(f_elements) >= 3 590 let b:js_menuinfo[f_elements[1].'('] = f_elements[2] 591 endif 592 endfor 593 594 " Get functions arguments 595 call map(arguments, 'matchstr(v:val, "function.\\{-}(\\zs.\\{-}\\ze)")') 596 let jargs = join(arguments, ',') 597 let jargs = substitute(jargs, '\s', '', 'g') 598 let arguments = split(jargs, ',') 599 let arguments = sort(arguments) 600 601 " Built-in functions 602 let builtin = ['alert(', 'confirm('] 603 604 " Top-level HTML DOM objects 605 let 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'] 606 call map(htmldom, 'v:val."."') 607 608 " Top-level properties 609 let properties = ['decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 610 \ 'eval', 'Infinity', 'isFinite', 'isNaN', 'NaN', 'Number', 'parseFloat', 611 \ 'parseInt', 'String', 'undefined', 'escape', 'unescape'] 612 613 " Keywords 614 let 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 616 let values = variables + functions + htmldom + arguments + builtin + properties + keywords 617 618 for m in values 619 if m =~? '^'.a:base 620 call add(res, m) 621 elseif m =~? a:base 622 call add(res2, m) 623 endif 624 endfor 625 626 let menu = res + res2 627 let final_menu = [] 628 for i in range(len(menu)) 629 let item = menu[i] 630 if item =~ '($' 631 let kind = 'f' 632 if has_key(b:js_menuinfo, item) 633 let m_info = b:js_menuinfo[item] 634 else 635 let m_info = '' 636 endif 637 else 638 let kind = 'v' 639 let m_info = '' 640 endif 641 let final_menu += [{'word':item, 'menu':m_info, 'kind':kind}] 642 endfor 643 let g:fm = final_menu 644 return final_menu 645 endif 646 647 endfunction 648 649 " vim:set foldmethod=marker: