LSP: Add support for external URLs with `documentLink` (#261)

pull/266/head
Mickaël Menu 2 years ago committed by GitHub
parent cdf4f8e0c1
commit c21c4fc21f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
## Unreleased
### Added
* LSP: Support for external URLs with `documentLink`.
### Fixed
* [#243](https://github.com/mickael-menu/zk/issues/243) LSP: Fixed finding backlink references for notes in a folder.

@ -281,15 +281,24 @@ func NewServer(opts ServerOpts) *Server {
documentLinks := []protocol.DocumentLink{}
for _, link := range links {
target, err := server.noteForLink(link, notebook)
if target == nil || err != nil {
continue
var target string
if strutil.IsURL(link.Href) {
// External link
target = link.Href
} else {
// Internal note link
targetNote, err := server.noteForLink(link, notebook)
if targetNote != nil && err == nil {
target = targetNote.URI
}
}
documentLinks = append(documentLinks, protocol.DocumentLink{
Range: link.Range,
Target: &target.URI,
})
if target != "" {
documentLinks = append(documentLinks, protocol.DocumentLink{
Range: link.Range,
Target: &target,
})
}
}
return documentLinks, err

Loading…
Cancel
Save