@@ -267,6 +267,40 @@ Handlebars.registerHelper("isliteral", (s: string) => {
267267 return s . match ( / ' .* ' / ) || s . match ( / " .* " / ) || s . match ( / \d + / ) ;
268268} ) ;
269269
270+
271+
272+ const typeMapping = new Map < string , string > ( [
273+ [ "string" , "String" ] ,
274+ [ "number" , "Integer" ] ,
275+ [ "boolean" , "bool" ] ,
276+ [ "null" , "nil" ] ,
277+ [ "undefined" , "nil" ] ,
278+ [ "any" , "untyped" ] ,
279+ [ "LSPAny" , "untyped" ] ,
280+ ] ) ;
281+
282+ const convertTypeToRbs : ( ( type : string ) => string ) = ( type ) => {
283+ if ( type . endsWith ( "[]" ) ) {
284+ return `Array[${ convertTypeToRbs ( type . slice ( 0 , - 2 ) ) } ]` ;
285+ }
286+ let rbsType = typeMapping . get ( type ) ;
287+ if ( rbsType != null ) {
288+ return rbsType ;
289+ }
290+
291+ return "untyped" ;
292+ } ;
293+
294+ Handlebars . registerHelper ( "method_signature" , ( members : InterfaceResult [ "members" ] ) => {
295+ return members
296+ . map (
297+ ( member ) =>
298+ `${ member . optional ? "?" : "" } ${ snake ( member . name ) } : ${ convertTypeToRbs ( member . type ) } ${ member . nullable ? "?" : "" } `
299+ )
300+ . join ( ", " ) ;
301+ } ) ;
302+ Handlebars . registerHelper ( "convertTypeToRbs" , convertTypeToRbs ) ;
303+
270304( async ( ) => {
271305 const data = globSync (
272306 path . join (
369403 ) ;
370404 } ) ;
371405
406+ interfaces . forEach ( ( definition ) => {
407+ createFile (
408+ path . join (
409+ rootDir ,
410+ "sig" ,
411+ "language_server" ,
412+ "protocol" ,
413+ "interface" ,
414+ `${ snake ( definition . interface . name ) } .rbs`
415+ ) ,
416+ Handlebars . compile (
417+ `
418+ module LanguageServer
419+ module Protocol
420+ module Interface
421+ {{#if definition.interface.documentation}}
422+ #
423+ {{comment definition.interface.documentation indent=6}}
424+ #
425+ {{/if}}
426+ class {{definition.interface.name}}
427+ def initialize: ({{method_signature definition.allMembers}}) -> void
428+
429+ @attributes: Hash[Symbol, untyped]
430+ attr_reader attributes: Hash[Symbol, untyped]
431+
432+ def to_hash: () -> Hash[Symbol, untyped]
433+
434+ def to_json: (*untyped) -> String
435+ end
436+ end
437+ end
438+ end
439+ ` . slice ( 1 ) ,
440+ { noEscape : true }
441+ ) ( { definition } )
442+ ) ;
443+ } ) ;
444+
372445 modules . forEach ( ( definition ) => {
373446 createFile (
374447 path . join (
412485 ) ;
413486 } ) ;
414487
488+ modules . forEach ( ( definition ) => {
489+ createFile (
490+ path . join (
491+ rootDir ,
492+ "sig" ,
493+ "language_server" ,
494+ "protocol" ,
495+ "constant" ,
496+ `${ snake ( definition . module . name ) } .rbs`
497+ ) ,
498+ Handlebars . compile (
499+ `
500+ module LanguageServer
501+ module Protocol
502+ module Constant
503+ {{#if definition.module.documentation}}
504+ #
505+ {{comment definition.module.documentation indent=6}}
506+ #
507+ {{/if}}
508+ module {{definition.module.name}}
509+ {{#each definition.members}}
510+ {{#if documentation}}
511+ #
512+ {{comment documentation indent=8}}
513+ #
514+ {{/if}}
515+ {{#if (isliteral value)}}
516+ {{const name}}: {{value}}
517+ {{else}}
518+ {{const name}}: {{convertTypeToRbs type}}
519+ {{/if}}
520+ {{/each}}
521+ end
522+ end
523+ end
524+ end
525+ ` . slice ( 1 ) ,
526+ { noEscape : true }
527+ ) ( { definition } )
528+ ) ;
529+ } ) ;
530+
415531 createFile (
416532 path . join ( rootDir , "lib" , "language_server" , "protocol" , "interface.rb" ) ,
417533 Handlebars . compile (
0 commit comments