robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ed194b99ac
master
1#!/usr/bin/env -S nvim -l 2-- Generates lua-ls annotations for lsp. 3 4local USAGE =[[ 5Generates lua-ls annotations for lsp. 6 7Also updates types in runtime/lua/vim/lsp/protocol.lua 8 9Usage: 10src/gen/gen_lsp.lua [options] 11 12Options: 13--version <version> LSP version to use (default: 3.18) 14--out <out> Output file (default: runtime/lua/vim/lsp/_meta/protocol.lua) 15--help Print this help message 16]] 17 18--- The LSP protocol JSON data (it's partial, non-exhaustive). 19--- https://raw.githubusercontent.com/microsoft/language-server-protocol/gh-pages/_specifications/lsp/3.18/metaModel/metaModel.schema.json 20--- @class vim._gen_lsp.Protocol 21--- @field requests vim._gen_lsp.Request[] 22--- @field notifications vim._gen_lsp.Notification[] 23--- @field structures vim._gen_lsp.Structure[] 24--- @field enumerations vim._gen_lsp.Enumeration[] 25--- @field typeAliases vim._gen_lsp.TypeAlias[] 26 27--- @class vim._gen_lsp.Notification 28--- @field deprecated? string 29--- @field documentation? string 30--- @field messageDirection string 31--- @field clientCapability? string 32--- @field serverCapability? string 33--- @field method vim.lsp.protocol.Method 34--- @field params? any 35--- @field proposed? boolean 36--- @field registrationMethod? string 37--- @field registrationOptions? any 38--- @field since? string 39 40--- @class vim._gen_lsp.Request : vim._gen_lsp.Notification 41--- @field errorData? any 42--- @field partialResult? any 43--- @field result any 44 45--- @class vim._gen_lsp.Structure translated to @class 46--- @field deprecated? string 47--- @field documentation? string 48--- @field extends? { kind: string, name: string }[] 49--- @field mixins? { kind: string, name: string }[] 50--- @field name string 51--- @field properties? vim._gen_lsp.Property[] members, translated to @field 52--- @field proposed? boolean 53--- @field since? string 54 55--- @class vim._gen_lsp.StructureLiteral translated to anonymous @class. 56--- @field deprecated? string 57--- @field description? string 58--- @field properties vim._gen_lsp.Property[] 59--- @field proposed? boolean 60--- @field since? string 61 62--- @class vim._gen_lsp.Property translated to @field 63--- @field deprecated? string 64--- @field documentation? string 65--- @field name string 66--- @field optional? boolean 67--- @field proposed? boolean 68--- @field since? string 69--- @field type { kind: string, name: string } 70 71--- @class vim._gen_lsp.Enumeration translated to @enum 72--- @field deprecated string? 73--- @field documentation string? 74--- @field name string? 75--- @field proposed boolean? 76--- @field since string? 77--- @field suportsCustomValues boolean? 78--- @field values { name: string, value: string, documentation?: string, since?: string }[] 79 80--- @class vim._gen_lsp.TypeAlias translated to @alias 81--- @field deprecated? string? 82--- @field documentation? string 83--- @field name string 84--- @field proposed? boolean 85--- @field since? string 86--- @field type vim._gen_lsp.Type 87 88--- @class vim._gen_lsp.Type 89--- @field kind string a common field for all Types. 90--- @field name? string for ReferenceType, BaseType 91--- @field element? any for ArrayType 92--- @field items? vim._gen_lsp.Type[] for OrType, AndType 93--- @field key? vim._gen_lsp.Type for MapType 94--- @field value? string|vim._gen_lsp.Type for StringLiteralType, MapType, StructureLiteralType 95 96--- @param fname string 97--- @param text string 98local function tofile ( fname , text ) 99local f =assert ( io . open ( fname , 'w' ), ( 'failed to open: %s' ): format ( fname )) 100f : write ( text ) 101f : close () 102( 'Written to:' , fname ) 103end 104 105---@param opt vim._gen_lsp.opt 106---@return vim._gen_lsp.Protocol 107local function read_json ( opt ) 108local uri ='https://raw.githubusercontent.com/microsoft/language-server-protocol/gh-pages/_specifications/lsp/' 109.. opt . version 110.. '/metaModel/metaModel.json' 111( 'Reading ' .. uri ) 112 113local res =vim . system ( { 'curl' , '--no-progress-meter' , uri , '-o' , '-' } ): wait () 114if res . code ~= 0 or ( res . stdout or '' ): len () < 999 then 115(( 'URL failed: %s' ): format ( uri )) 116vim . ( res ) 117error ( res . stdout ) 118end 119return vim . json . decode ( res . stdout ) 120end 121 122--- Gets the Lua symbol for a given fully-qualified LSP method name. 123--- @param s string 124--- @return string 125local function to_luaname ( s ) 126-- "$/" prefix is special: https://microsoft.github.io/language-server-protocol/specification/#dollarRequests 127return ( s : gsub ( '^%$' , 'dollar' ): gsub ( '/' , '_' )) 128end 129 130--- @param a vim._gen_lsp.Notification 131--- @param b vim._gen_lsp.Notification 132--- @return boolean 133local function compare_method ( a , b ) 134return to_luaname ( a . method ) < to_luaname ( b . method ) 135end 136 137--- @param item vim._gen_lsp.Request|vim._gen_lsp.Notification 138--- @return string? 139local function registration_provider ( item ) 140local server_capability =item . serverCapability 141if not server_capability then 142return nil 143end 144if vim . startswith ( server_capability , 'workspace.' ) then 145return server_capability 146end 147return server_capability : match ( '^[^%.]+' ) 148end 149 150---@param structures table<string,vim._gen_lsp.Structure> 151---@param type vim._gen_lsp.Type 152---@param seen? table<string,true> 153---@return boolean 154local function supports_static_registration ( structures , type , seen ) 155if type . kind == 'reference' then 156if type . name == 'StaticRegistrationOptions' then 157return true 158end 159 160seen =seen or {} 161if seen [ type . name ] then 162return false 163end 164seen [ type . name ] =true 165 166local structure =structures [ type . name ] 167if not structure then 168return false 169end 170local bases ={} 171vim . list_extend ( bases , structure . extends or {} ) 172vim . list_extend ( bases , structure . mixins or {} ) 173for _ , base in ipairs ( bases ) do 174if supports_static_registration ( structures , base , seen ) then 175return true 176end 177end 178elseif type . kind == 'and' or type . kind == 'or' then 179for _ , item in ipairs ( type . items ) do 180if supports_static_registration ( structures , item , seen ) then 181return true 182end 183end 184end 185 186return false 187end 188 189---@param protocol vim._gen_lsp.Protocol 190local function write_to_vim_protocol ( protocol ) 191local all ={} --- @type (vim._gen_lsp.Request|vim._gen_lsp.Notification)[] 192vim . list_extend ( all , protocol . notifications ) 193vim . list_extend ( all , protocol . requests ) 194 195local structures ={} --- @type table<string,vim._gen_lsp.Structure> 196for _ , structure in ipairs ( protocol . structures ) do 197structures [ structure . name ] =structure 198end 199 200table . sort ( all , compare_method ) 201table . sort ( protocol . requests , compare_method ) 202table . sort ( protocol . notifications , compare_method ) 203 204local output ={ '-- Generated by gen_lsp.lua, keep at end of file.' } 205 206do -- methods 207for _ , dir in ipairs ( { 'clientToServer' , 'serverToClient' } ) do 208local dir1 =dir : sub ( 1 , 1 ): upper () .. dir : sub ( 2 ) 209local alias =( 'vim.lsp.protocol.Method.%s' ): format ( dir1 ) 210for _ , b in ipairs ( { 211{ title ='Request' , methods =protocol . requests } , 212{ title ='Notification' , methods =protocol . notifications } , 213} ) do 214output [ # output + 1 ] =( '--- LSP %s (direction: %s)' ): format ( b . title , dir ) 215output [ # output + 1 ] =( '--- @alias %s.%s' ): format ( alias , b . title ) 216for _ , item in ipairs ( b . methods ) do 217if item . messageDirection == dir or item . messageDirection == 'both' then 218output [ # output + 1 ] =( "--- | '%s'," ): format ( item . method ) 219end 220end 221output [ # output + 1 ] ='' 222end 223 224vim . list_extend ( output , { 225( '--- LSP Message (direction: %s).' ): format ( dir ), 226( '--- @alias %s' ): format ( alias ), 227( '--- | %s.Request' ): format ( alias ), 228( '--- | %s.Notification' ): format ( alias ), 229'' , 230} ) 231end 232 233vim . list_extend ( output , { 234'--- @alias vim.lsp.protocol.Method' , 235'--- | vim.lsp.protocol.Method.ClientToServer' , 236'--- | vim.lsp.protocol.Method.ServerToClient' , 237'' , 238'-- Generated by gen_lsp.lua, keep at end of file.' , 239'--- @deprecated Use `vim.lsp.protocol.Method` instead.' , 240'--- @enum vim.lsp.protocol.Methods' , 241'--- @see https://microsoft.github.io/language-server-protocol/specification/#metaModel' , 242'--- LSP method names.' , 243'protocol.Methods = {' , 244} ) 245 246for _ , item in ipairs ( all ) do 247if item . method then 248if item . documentation then 249local document =vim . split ( item . documentation , '\n?\n' , { trimempty =true } ) 250for _ , docstring in ipairs ( document ) do 251output [ # output + 1 ] =' --- ' .. docstring 252end 253end 254output [ # output + 1 ] =( " %s = '%s'," ): format ( to_luaname ( item . method ), item . method ) 255end 256end 257output [ # output + 1 ] ='}' 258end 259 260do -- registrationMethods 261local found ={} --- @type table<string, boolean> 262vim . list_extend ( output , { 263'' , 264'-- Generated by gen_lsp.lua, keep at end of file.' , 265'--- LSP registration methods' , 266'---@alias vim.lsp.protocol.Method.Registration' , 267} ) 268for _ , item in ipairs ( all ) do 269if item . registrationMethod and not found [ item . registrationMethod ] then 270vim . list_extend ( output , { 271( "--- | '%s'" ): format ( item . registrationMethod or item . method ), 272} ) 273found [ item . registrationMethod or item . method ] =true 274end 275end 276end 277 278do -- capabilities 279vim . list_extend ( output , { 280'' , 281'-- stylua: ignore start' , 282'-- Generated by gen_lsp.lua, keep at end of file.' , 283'--- Maps method names to the required client capability' , 284'protocol._provider_to_client_registration = {' , 285} ) 286 287local providers ={} --- @type table<string, string> 288for _ , item in ipairs ( all ) do 289local provider =registration_provider ( item ) 290if item . registrationOptions and not providers [ provider ] and item . clientCapability then 291if 292item . clientCapability == item . serverCapability 293and not ( item . serverCapability and vim . startswith ( item . serverCapability , 'workspace.' )) 294then 295provider =nil 296end 297local key =provider or item . method 298providers [ key ] =item . clientCapability 299end 300end 301 302---@type { provider: string, path : string }[] 303local found_entries ={} 304for key , value in pairs ( providers ) do 305found_entries [ # found_entries + 1 ] ={ provider =key , path =value } 306end 307table . sort ( found_entries , function ( a , b ) 308return a . provider < b . provider 309end ) 310for _ , entry in ipairs ( found_entries ) do 311output [ # output + 1 ] =( " ['%s'] = { %s }," ): format ( 312entry . provider , 313"'" .. entry . path : gsub ( '%.' , "', '" ) .. "'" 314) 315end 316 317output [ # output + 1 ] ='}' 318output [ # output + 1 ] ='-- stylua: ignore end' 319 320vim . list_extend ( output , { 321'' , 322'-- stylua: ignore start' , 323'-- Generated by gen_lsp.lua, keep at end of file.' , 324'--- Maps method names to dynamic/static registration providers' , 325'protocol._request_name_to_registration_provider = {' , 326} ) 327 328for _ , item in ipairs ( all ) do 329local provider =registration_provider ( item ) or item . method 330output [ # output + 1 ] =( " ['%s'] = '%s'," ): format ( item . method , provider ) 331end 332 333output [ # output + 1 ] ='}' 334output [ # output + 1 ] ='-- stylua: ignore end' 335 336vim . list_extend ( output , { 337'' , 338'-- stylua: ignore start' , 339'-- Generated by gen_lsp.lua, keep at end of file.' , 340'--- Maps method names to the required server capability' , 341'-- A server capability equal to the method means there is no related server capability' , 342'protocol._request_name_to_server_capability = {' , 343} ) 344 345for _ , item in ipairs ( all ) do 346output [ # output + 1 ] =( " ['%s'] = { %s }," ): format ( 347item . method , 348"'" .. ( item . serverCapability or item . method ): gsub ( '%.' , "', '" ) .. "'" 349) 350end 351 352---@type table<string, string[]> 353local registration_capability ={} 354for _ , item in ipairs ( all ) do 355if item . serverCapability then 356if item . registrationMethod and item . registrationMethod ~= item . method then 357local registrationMethod =item . registrationMethod 358assert ( registrationMethod , 'registrationMethod is nil' ) 359if not registration_capability [ item . registrationMethod ] then 360registration_capability [ registrationMethod ] ={} 361end 362table . insert ( registration_capability [ registrationMethod ], item . serverCapability ) 363end 364end 365end 366 367for registrationMethod , capabilities in pairs ( registration_capability ) do 368output [ # output + 1 ] =( " ['%s'] = { '%s' }," ): format ( 369registrationMethod , 370vim . iter ( capabilities ): fold ( capabilities [ 1 ], function ( acc , v ) 371return # v < # acc and v or acc 372end ) 373) 374end 375 376output [ # output + 1 ] ='}' 377output [ # output + 1 ] ='-- stylua: ignore end' 378 379vim . list_extend ( output , { 380'' , 381'-- stylua: ignore start' , 382'-- Generated by gen_lsp.lua, keep at end of file.' , 383'protocol._method_supports_dynamic_registration = {' , 384} ) 385 386--- These methods have no registrationOptions but can still be registered 387--- TODO: remove if resolved upstream: https://github.com/microsoft/language-server-protocol/issues/2218 388local methods_with_no_registration_options ={ 389[ 'workspace/didChangeWorkspaceFolders' ] =true , 390} 391 392for _ , item in ipairs ( all ) do 393if 394item . registrationMethod 395or item . registrationOptions 396or methods_with_no_registration_options [ item . method ] 397then 398output [ # output + 1 ] =( " ['%s'] = %s," ): format ( item . method , true ) 399end 400end 401 402output [ # output + 1 ] ='}' 403output [ # output + 1 ] ='-- stylua: ignore end' 404 405vim . list_extend ( output , { 406'' , 407'-- stylua: ignore start' , 408'-- Generated by gen_lsp.lua, keep at end of file.' , 409'protocol._method_supports_static_registration = {' , 410} ) 411 412local static_registration_providers ={} --- @type table<string,true> 413for _ , item in ipairs ( all ) do 414if 415item . registrationOptions 416and item . serverCapability 417and supports_static_registration ( structures , item . registrationOptions ) 418then 419static_registration_providers [ registration_provider ( item )] =true 420end 421end 422 423for _ , item in ipairs ( all ) do 424local provider =registration_provider ( item ) 425local has_static_registration =item . registrationOptions 426and supports_static_registration ( structures , item . registrationOptions ) 427if 428item . serverCapability 429and static_registration_providers [ provider ] 430and ( has_static_registration or item . serverCapability == provider ) 431then 432output [ # output + 1 ] =( " ['%s'] = %s," ): format ( item . method , true ) 433end 434end 435 436output [ # output + 1 ] ='}' 437output [ # output + 1 ] ='-- stylua: ignore end' 438 439vim . list_extend ( output , { 440'' , 441'-- stylua: ignore start' , 442'-- Generated by gen_lsp.lua, keep at end of file.' , 443'-- These methods have no registration options but can still be registered dynamically.' , 444'protocol._methods_with_no_registration_options = {' , 445} ) 446for key , v in pairs ( methods_with_no_registration_options ) do 447output [ # output + 1 ] =( " ['%s'] = %s ," ): format ( key , v ) 448end 449output [ # output + 1 ] ='}' 450output [ # output + 1 ] ='-- stylua: ignore end' 451end 452 453output [ # output + 1 ] ='' 454output [ # output + 1 ] ='return protocol' 455 456local fname ='./runtime/lua/vim/lsp/protocol.lua' 457local bufnr =vim . fn . bufadd ( fname ) 458vim . fn . bufload ( bufnr ) 459vim . api . nvim_set_current_buf ( bufnr ) 460local lines =vim . api . nvim_buf_get_lines ( bufnr , 0 , - 1 , false ) 461local index =vim . iter ( ipairs ( lines )): find ( function ( key , item ) 462return vim . startswith ( item , '-- Generated by' ) and key or nil 463end ) 464index =index and index - 1 or vim . api . nvim_buf_line_count ( bufnr ) - 1 465vim . api . nvim_buf_set_lines ( bufnr , index , - 1 , true , output ) 466vim . cmd . write () 467end 468 469--- @param doc string 470local function process_documentation ( doc ) 471doc =doc : gsub ( '\n' , '\n---' ) 472-- Remove <200b> (zero-width space) unicode characters: e.g., `**/<200b>*` 473doc =doc : gsub ( '\226\128\139' , '' ) 474-- Escape annotations that are not recognized by lua-ls 475doc =doc : gsub ( '%^---@sample' , '---\\@sample' ) 476return '---' .. doc 477end 478 479local simple_types ={ 480string =true , 481boolean =true , 482integer =true , 483uinteger =true , 484decimal =true , 485} 486 487local anonymous_num =0 488 489--- @type string[] 490local anonym_classes ={} 491 492--- @param type vim._gen_lsp.Type 493--- @param prefix? string Optional prefix associated with the this type, made of (nested) field name. 494--- Used to generate class name for structure literal types. 495--- @return string 496local function parse_type ( type , prefix ) 497if type . kind == 'reference' or type . kind == 'base' then 498if type . kind == 'base' and type . name == 'string' and prefix == 'method' then 499return 'vim.lsp.protocol.Method' 500end 501if simple_types [ type . name ] then 502return type . name 503end 504return 'lsp.' .. type . name 505elseif type . kind == 'array' then 506local parsed_items =parse_type ( type . element , prefix ) 507if type . element . items and # type . element . items > 1 then 508parsed_items ='(' .. parsed_items .. ')' 509end 510return parsed_items .. '[]' 511elseif type . kind == 'or' then 512local types ={} --- @type string[] 513for _ , item in ipairs ( type . items ) do 514types [ # types + 1 ] =parse_type ( item , prefix ) 515end 516return table . concat ( types , '|' ) 517elseif type . kind == 'stringLiteral' then 518return '"' .. type . value .. '"' 519elseif type . kind == 'map' then 520local key =assert ( type . key ) 521local value =type . value --[[ @as vim._gen_lsp.Type ]] 522return ( 'table<%s, %s>' ): format ( parse_type ( key , prefix ), parse_type ( value , prefix )) 523elseif type . kind == 'literal' then 524-- can I use ---@param disabled? {reason: string} 525-- use | to continue the inline class to be able to add docs 526-- https://github.com/LuaLS/lua-language-server/issues/2128 527anonymous_num =anonymous_num + 1 528local anonymous_classname ='lsp._anonym' .. anonymous_num 529if prefix then 530anonymous_classname =anonymous_classname .. '.' .. prefix 531end 532 533local anonym ={ '---@class ' .. anonymous_classname } 534if anonymous_num > 1 then 535table . insert ( anonym , 1 , '' ) 536end 537 538---@type vim._gen_lsp.StructureLiteral 539local structural_literal =assert ( type . value ) --[[ @as vim._gen_lsp.StructureLiteral ]] 540for _ , field in ipairs ( structural_literal . properties ) do 541anonym [ # anonym + 1 ] ='---' 542if field . documentation then 543anonym [ # anonym + 1 ] =process_documentation ( field . documentation ) 544end 545anonym [ # anonym + 1 ] =( '---@field %s%s %s' ): format ( 546field . name , 547( field . optional and '?' or '' ), 548parse_type ( field . type , prefix .. '.' .. field . name ) 549) 550end 551for _ , line in ipairs ( anonym ) do 552if line then 553anonym_classes [ # anonym_classes + 1 ] =line 554end 555end 556return anonymous_classname 557elseif type . kind == 'tuple' then 558local types ={} --- @type string[] 559for _ , value in ipairs ( type . items ) do 560types [ # types + 1 ] =parse_type ( value , prefix ) 561end 562return '[' .. table . concat ( types , ', ' ) .. ']' 563end 564 565vim . ( 'WARNING: Unknown type ' , type ) 566return '' 567end 568 569--- @param protocol vim._gen_lsp.Protocol 570--- @param version string 571--- @param output_file string 572local function write_to_meta_protocol ( protocol , version , output_file ) 573local output ={ 574'--' .. '[[' , 575'THIS FILE IS GENERATED by src/gen/gen_lsp.lua' , 576'DO NOT EDIT MANUALLY' , 577'' , 578'Based on LSP protocol ' .. version , 579'' , 580'Regenerate:' , 581( [=[nvim -l src/gen/gen_lsp.lua --version %s]=] ): format ( version ), 582'--' .. ']]' , 583'' , 584'---@meta' , 585"error('Cannot require a meta file')" , 586'' , 587'---@alias lsp.null vim.NIL' , 588'---@alias uinteger integer' , 589'---@alias decimal number' , 590'---@alias lsp.DocumentUri string' , 591'---@alias lsp.URI string' , 592'' , 593} 594 595for _ , structure in ipairs ( protocol . structures ) do 596if structure . documentation then 597output [ # output + 1 ] =process_documentation ( structure . documentation ) 598end 599local class_string =( '---@class lsp.%s' ): format ( structure . name ) 600if structure . extends or structure . mixins then 601local inherits_from =table . concat ( 602vim . list_extend ( 603vim . tbl_map ( parse_type , structure . extends or {} ), 604vim . tbl_map ( parse_type , structure . mixins or {} ) 605), 606', ' 607) 608class_string =class_string .. ': ' .. inherits_from 609end 610output [ # output + 1 ] =class_string 611 612for _ , field in ipairs ( structure . properties or {} ) do 613output [ # output + 1 ] ='---' -- Insert a single newline between @fields (and after @class) 614if field . documentation then 615output [ # output + 1 ] =process_documentation ( field . documentation ) 616end 617output [ # output + 1 ] =( '---@field %s%s %s' ): format ( 618field . name , 619( field . optional and '?' or '' ), 620parse_type ( field . type , field . name ) 621) 622end 623output [ # output + 1 ] ='' 624end 625 626for _ , enum in ipairs ( protocol . enumerations ) do 627if enum . documentation then 628output [ # output + 1 ] =process_documentation ( enum . documentation ) 629end 630output [ # output + 1 ] ='---@alias lsp.' .. enum . name 631for _ , value in ipairs ( enum . values ) do 632local value1 =( type ( value . value ) == 'string' and ( '"%s"' ): format ( value . value ) or value . value ) 633output [ # output + 1 ] =( '---| %s # %s' ): format ( value1 , value . name ) 634end 635output [ # output + 1 ] ='' 636end 637 638for _ , alias in ipairs ( protocol . typeAliases ) do 639if alias . documentation then 640output [ # output + 1 ] =process_documentation ( alias . documentation ) 641end 642 643local alias_type --- @type string 644 645if alias . type . kind == 'or' then 646local alias_types ={} --- @type string[] 647for _ , item in ipairs ( alias . type . items ) do 648alias_types [ # alias_types + 1 ] =parse_type ( item , alias . name ) 649end 650alias_type =table . concat ( alias_types , '|' ) 651else 652alias_type =parse_type ( alias . type , alias . name ) 653end 654output [ # output + 1 ] =( '---@alias lsp.%s %s' ): format ( alias . name , alias_type ) 655output [ # output + 1 ] ='' 656end 657 658-- anonymous classes 659vim . list_extend ( output , anonym_classes ) 660 661tofile ( output_file , table . concat ( output , '\n' ) .. '\n' ) 662end 663 664---@class vim._gen_lsp.opt 665---@field output_file string 666---@field version string 667 668--- @return vim._gen_lsp.opt 669local function parse_args () 670---@type vim._gen_lsp.opt 671local opt ={ 672output_file ='runtime/lua/vim/lsp/_meta/protocol.lua' , 673version ='3.18' , 674} 675 676local i =1 677while i <= # _G . arg do 678local cur_arg =_G . arg [ i ] 679if cur_arg == '--out' then 680opt . output_file =assert ( _G . arg [ i + 1 ], '--out <outfile> needed' ) 681i =i + 1 682elseif cur_arg == '--version' then 683opt . version =assert ( _G . arg [ i + 1 ], '--version <version> needed' ) 684i =i + 1 685elseif cur_arg == '--help' or cur_arg == '-h' then 686( USAGE ) 687os . exit ( 0 ) 688elseif vim . startswith ( cur_arg , '-' ) then 689( 'Unrecognized option:' , cur_arg , '\n' ) 690os . exit ( 1 ) 691end 692i =i + 1 693end 694 695return opt 696end 697 698local function main () 699local opt =parse_args () 700local protocol =read_json ( opt ) 701write_to_vim_protocol ( protocol ) 702write_to_meta_protocol ( protocol , opt . version , opt . output_file ) 703end 704 705main ()