@@ -11,7 +11,7 @@ type Settings = Partial<FullSettings>
1111
1212function connectTo ( address : string ) : Promise < rpc . MessageConnection > {
1313 return new Promise ( resolve => {
14- const webSocket = new WebSocket ( 'ws://' + address )
14+ const webSocket = new WebSocket ( address )
1515 rpc . listen ( {
1616 webSocket,
1717 onConnection : ( connection : rpc . MessageConnection ) => {
@@ -22,47 +22,55 @@ function connectTo(address: string): Promise<rpc.MessageConnection> {
2222}
2323
2424export function activate ( ) : void {
25- const address = sourcegraph . configuration . get < Settings > ( ) . get ( 'graphql.langserver-address' )
26- if ( ! address ) {
27- console . log ( 'No graphql.langserver- address was set, exiting.' )
28- return
29- }
30- console . log ( 'Connecting to' , address )
25+ function afterActivate ( ) {
26+ const address = sourcegraph . configuration . get < Settings > ( ) . get ( 'graphql.langserver- address' )
27+ if ( ! address ) {
28+ console . log ( 'No graphql.langserver-address was set, exiting.' )
29+ return
30+ }
3131
32- connectTo ( address ) . then ( ( connection : rpc . MessageConnection ) => {
33- console . log ( 'Connected' )
34- connection . listen ( )
32+ connectTo ( address ) . then ( ( connection : rpc . MessageConnection ) => {
33+ connection . listen ( )
3534
36- sourcegraph . languages . registerHoverProvider ( [ '*' ] , {
37- provideHover : async ( doc , pos ) => {
38- return connection . sendRequest < sourcegraph . Hover > ( 'hover' , doc , pos ) . then ( hover => {
39- return (
40- hover && {
41- contents : {
42- value : '```python\n' + ( hover . contents as any ) . join ( '\n' ) + '\n```' ,
43- kind : sourcegraph . MarkupKind . Markdown ,
44- } ,
45- }
46- )
47- } )
48- } ,
49- } )
35+ const docSelector = [ { pattern : '*.{graphql,gql,schema}' } ]
36+
37+ sourcegraph . languages . registerHoverProvider ( docSelector , {
38+ provideHover : async ( doc , pos ) => {
39+ return connection . sendRequest < sourcegraph . Hover > ( 'hover' , doc , pos ) . then ( hover => {
40+ return (
41+ hover && {
42+ contents : {
43+ value : '```python\n' + ( hover . contents as any ) . join ( '\n' ) + '\n```' ,
44+ kind : sourcegraph . MarkupKind . Markdown ,
45+ } ,
46+ }
47+ )
48+ } )
49+ } ,
50+ } )
5051
51- sourcegraph . languages . registerDefinitionProvider ( [ '*' ] , {
52- provideDefinition : async ( doc , pos ) => {
53- return connection . sendRequest < any > ( 'definition' , doc , pos ) . then ( definition => {
54- return (
55- definition &&
56- new sourcegraph . Location (
57- new sourcegraph . URI ( doc . uri ) ,
58- new sourcegraph . Range (
59- new sourcegraph . Position ( definition . start . line , definition . start . character ) ,
60- new sourcegraph . Position ( definition . end . line , definition . end . character )
52+ sourcegraph . languages . registerDefinitionProvider ( docSelector , {
53+ provideDefinition : async ( doc , pos ) => {
54+ return connection . sendRequest < any > ( 'definition' , doc , pos ) . then ( definition => {
55+ return (
56+ definition &&
57+ new sourcegraph . Location (
58+ new sourcegraph . URI ( doc . uri ) ,
59+ new sourcegraph . Range (
60+ new sourcegraph . Position ( definition . start . line , definition . start . character ) ,
61+ new sourcegraph . Position ( definition . end . line , definition . end . character )
62+ )
6163 )
6264 )
63- )
64- } )
65- } ,
65+ } )
66+ } ,
67+ } )
6668 } )
67- } )
69+ }
70+ // Error creating extension host: Error: Configuration is not yet available.
71+ // `sourcegraph.configuration.get` is not usable until after the extension
72+ // `activate` function is finished executing. This is a known issue and will
73+ // be fixed before the beta release of Sourcegraph extensions. In the
74+ // meantime, work around this limitation by deferring calls to `get`.
75+ setTimeout ( afterActivate , 0 )
6876}
0 commit comments