@@ -719,7 +719,7 @@ func (c *commandHandler) Doc(ctx context.Context, args command.DocArgs) (protoco
719
719
// Direct the client to open the /pkg page.
720
720
result = web .PkgURL (deps .snapshot .View ().ID (), pkgpath , fragment )
721
721
if args .ShowDocument {
722
- openClientBrowser (ctx , c .s .client , result )
722
+ openClientBrowser (ctx , c .s .client , "Doc" , result , c . s . Options () )
723
723
}
724
724
725
725
return nil
@@ -1158,7 +1158,7 @@ func (c *commandHandler) StartDebugging(ctx context.Context, args command.Debugg
1158
1158
return result , fmt .Errorf ("starting debug server: %w" , err )
1159
1159
}
1160
1160
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 () )
1162
1162
return result , nil
1163
1163
}
1164
1164
@@ -1560,20 +1560,39 @@ func showMessage(ctx context.Context, cli protocol.Client, typ protocol.MessageT
1560
1560
1561
1561
// openClientBrowser causes the LSP client to open the specified URL
1562
1562
// 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
+ }
1565
1578
}
1566
1579
1567
1580
// openClientEditor causes the LSP client to open the specified document
1568
1581
// and select the indicated range.
1569
1582
//
1570
1583
// Note that VS Code 1.87.2 doesn't currently raise the window; this is
1571
1584
// 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 )
1574
1590
}
1575
1591
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
+ }
1577
1596
// In principle we shouldn't send a showDocument request to a
1578
1597
// client that doesn't support it, as reported by
1579
1598
// ShowDocumentClientCapabilities. But even clients that do
@@ -1690,7 +1709,7 @@ func (c *commandHandler) FreeSymbols(ctx context.Context, viewID string, loc pro
1690
1709
return err
1691
1710
}
1692
1711
url := web .freesymbolsURL (viewID , loc )
1693
- openClientBrowser (ctx , c .s .client , url )
1712
+ openClientBrowser (ctx , c .s .client , "Free symbols" , url , c . s . Options () )
1694
1713
return nil
1695
1714
}
1696
1715
@@ -1700,12 +1719,14 @@ func (c *commandHandler) Assembly(ctx context.Context, viewID, packageID, symbol
1700
1719
return err
1701
1720
}
1702
1721
url := web .assemblyURL (viewID , packageID , symbol )
1703
- openClientBrowser (ctx , c .s .client , url )
1722
+ openClientBrowser (ctx , c .s .client , "Assembly" , url , c . s . Options () )
1704
1723
return nil
1705
1724
}
1706
1725
1707
1726
func (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 ())
1709
1730
return nil
1710
1731
}
1711
1732
0 commit comments