@@ -719,7 +719,7 @@ func (c *commandHandler) Doc(ctx context.Context, args command.DocArgs) (protoco
719719 // Direct the client to open the /pkg page.
720720 result = web .PkgURL (deps .snapshot .View ().ID (), pkgpath , fragment )
721721 if args .ShowDocument {
722- openClientBrowser (ctx , c .s .client , result )
722+ openClientBrowser (ctx , c .s .client , "Doc" , result , c . s . Options () )
723723 }
724724
725725 return nil
@@ -1158,7 +1158,7 @@ func (c *commandHandler) StartDebugging(ctx context.Context, args command.Debugg
11581158 return result , fmt .Errorf ("starting debug server: %w" , err )
11591159 }
11601160 result .URLs = []string {"http://" + listenedAddr }
1161- openClientBrowser (ctx , c .s .client , result .URLs [0 ])
1161+ openClientBrowser (ctx , c .s .client , "Debug" , result .URLs [0 ], c . s . Options () )
11621162 return result , nil
11631163}
11641164
@@ -1560,20 +1560,39 @@ func showMessage(ctx context.Context, cli protocol.Client, typ protocol.MessageT
15601560
15611561// openClientBrowser causes the LSP client to open the specified URL
15621562// in an external browser.
1563- func openClientBrowser (ctx context.Context , cli protocol.Client , url protocol.URI ) {
1564- showDocumentImpl (ctx , cli , url , nil )
1563+ //
1564+ // If the client does not support window/showDocument, a window/showMessage
1565+ // request is instead used, with the format "$title: open your browser to $url".
1566+ func openClientBrowser (ctx context.Context , cli protocol.Client , title string , url protocol.URI , opts * settings.Options ) {
1567+ if opts .ShowDocumentSupported {
1568+ showDocumentImpl (ctx , cli , url , nil , opts )
1569+ } else {
1570+ params := & protocol.ShowMessageParams {
1571+ Type : protocol .Info ,
1572+ Message : fmt .Sprintf ("%s: open your browser to %s" , title , url ),
1573+ }
1574+ if err := cli .ShowMessage (ctx , params ); err != nil {
1575+ event .Error (ctx , "failed to show brower url" , err )
1576+ }
1577+ }
15651578}
15661579
15671580// openClientEditor causes the LSP client to open the specified document
15681581// and select the indicated range.
15691582//
15701583// Note that VS Code 1.87.2 doesn't currently raise the window; this is
15711584// https://github.com/microsoft/vscode/issues/207634
1572- func openClientEditor (ctx context.Context , cli protocol.Client , loc protocol.Location ) {
1573- showDocumentImpl (ctx , cli , protocol .URI (loc .URI ), & loc .Range )
1585+ func openClientEditor (ctx context.Context , cli protocol.Client , loc protocol.Location , opts * settings.Options ) {
1586+ if ! opts .ShowDocumentSupported {
1587+ return // no op
1588+ }
1589+ showDocumentImpl (ctx , cli , protocol .URI (loc .URI ), & loc .Range , opts )
15741590}
15751591
1576- func showDocumentImpl (ctx context.Context , cli protocol.Client , url protocol.URI , rangeOpt * protocol.Range ) {
1592+ func showDocumentImpl (ctx context.Context , cli protocol.Client , url protocol.URI , rangeOpt * protocol.Range , opts * settings.Options ) {
1593+ if ! opts .ShowDocumentSupported {
1594+ return // no op
1595+ }
15771596 // In principle we shouldn't send a showDocument request to a
15781597 // client that doesn't support it, as reported by
15791598 // ShowDocumentClientCapabilities. But even clients that do
@@ -1690,7 +1709,7 @@ func (c *commandHandler) FreeSymbols(ctx context.Context, viewID string, loc pro
16901709 return err
16911710 }
16921711 url := web .freesymbolsURL (viewID , loc )
1693- openClientBrowser (ctx , c .s .client , url )
1712+ openClientBrowser (ctx , c .s .client , "Free symbols" , url , c . s . Options () )
16941713 return nil
16951714}
16961715
@@ -1700,12 +1719,14 @@ func (c *commandHandler) Assembly(ctx context.Context, viewID, packageID, symbol
17001719 return err
17011720 }
17021721 url := web .assemblyURL (viewID , packageID , symbol )
1703- openClientBrowser (ctx , c .s .client , url )
1722+ openClientBrowser (ctx , c .s .client , "Assembly" , url , c . s . Options () )
17041723 return nil
17051724}
17061725
17071726func (c * commandHandler ) ClientOpenURL (ctx context.Context , url string ) error {
1708- openClientBrowser (ctx , c .s .client , url )
1727+ // Fall back to "Gopls: open your browser..." if we must send a showMessage
1728+ // request, since we don't know the context of this command.
1729+ openClientBrowser (ctx , c .s .client , "Gopls" , url , c .s .Options ())
17091730 return nil
17101731}
17111732
0 commit comments