Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package zk for openSUSE:Factory checked in 
at 2023-02-14 16:45:11
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/zk (Old)
 and      /work/SRC/openSUSE:Factory/.zk.new.27156 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "zk"

Tue Feb 14 16:45:11 2023 rev:4 rq:1065687 version:0.13.0

Changes:
--------
--- /work/SRC/openSUSE:Factory/zk/zk.changes    2023-01-12 22:45:16.185193840 
+0100
+++ /work/SRC/openSUSE:Factory/.zk.new.27156/zk.changes 2023-02-14 
16:45:37.986517279 +0100
@@ -1,0 +2,9 @@
+Mon Feb 13 11:57:07 UTC 2023 - Soc Virnyl Estela <[email protected]>
+
+- Update to version 0.13.0:
+  * zk.new now returns the created note's content in its output (content), and 
has two new options:
+  * dryRun will prevent zk.new from creating the note on the file system.
+  * insertContentAtLocation can be used to insert the created note's content 
into an arbitrary location.
+  * A new zk.link command to insert a link to a given note
+
+-------------------------------------------------------------------

Old:
----
  vendor.tar.gz
  zk-0.12.0.tar.gz

New:
----
  vendor.tar.zstd
  zk-0.13.0.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ zk.spec ++++++
--- /var/tmp/diff_new_pack.ilAEoB/_old  2023-02-14 16:45:39.798527978 +0100
+++ /var/tmp/diff_new_pack.ilAEoB/_new  2023-02-14 16:45:39.802528001 +0100
@@ -17,15 +17,16 @@
 
 
 Name:           zk
-Version:        0.12.0
+Version:        0.13.0
 Release:        0
 Summary:        Plain text note-taking assistant for markdown
 License:        BSD-2-Clause
 Group:          System/Shells
 URL:            https://github.com/mickael-menu/zk
 Source0:        
https://github.com/mickael-menu/zk/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
-Source1:        vendor.tar.gz
+Source1:        vendor.tar.zstd
 BuildRequires:  c_compiler
+BuildRequires:  zstd
 BuildRequires:  golang(API)
 BuildRequires:  pkgconfig(icu-io)
 BuildRequires:  pkgconfig(sqlite3)

++++++ zk-0.12.0.tar.gz -> zk-0.13.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/zk-0.12.0/.github/workflows/triage.yml 
new/zk-0.13.0/.github/workflows/triage.yml
--- old/zk-0.12.0/.github/workflows/triage.yml  2022-12-04 10:12:48.000000000 
+0100
+++ new/zk-0.13.0/.github/workflows/triage.yml  2023-02-13 08:23:21.000000000 
+0100
@@ -16,7 +16,7 @@
   stale:
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/stale@v6
+      - uses: actions/stale@v7
         with:
           days-before-stale: 30
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/zk-0.12.0/CHANGELOG.md new/zk-0.13.0/CHANGELOG.md
--- old/zk-0.12.0/CHANGELOG.md  2022-12-04 10:12:48.000000000 +0100
+++ new/zk-0.13.0/CHANGELOG.md  2023-02-13 08:23:21.000000000 +0100
@@ -4,6 +4,16 @@
 
 <!--## Unreleased-->
 
+## 0.13.0
+
+### Added
+
+* LSP:
+    * `zk.new` now returns the created note's content in its output 
(`content`), and has two new options:
+        * `dryRun` will prevent `zk.new` from creating the note on the file 
system.
+        * `insertContentAtLocation` can be used to insert the created note's 
content into an arbitrary location.
+    * A new `zk.link` command to insert a link to a given note (contributed by 
[@psanker](https://github.com/mickael-menu/zk/pull/284)).
+
 ## 0.12.0
 
 ### Added
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/zk-0.12.0/README.md new/zk-0.13.0/README.md
--- old/zk-0.12.0/README.md     2022-12-04 10:12:48.000000000 +0100
+++ new/zk-0.13.0/README.md     2023-02-13 08:23:21.000000000 +0100
@@ -94,5 +94,6 @@
 ## Related projects
 
 * [Neuron](https://github.com/srid/neuron) – a great tool to publish a 
Zettelkasten on the web
-* [Emanote](https://emanote.srid.ca/) - an improved successor to Neuron
+* [Emanote](https://emanote.srid.ca/) – an improved successor to Neuron
 * [sirupsen's zk](https://github.com/sirupsen/zk) – a collection of scripts 
with a similar purpose
+* [zk-spaced](https://github.com/matze/zk-spaced) – spaced repetition plugin 
for zk
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/zk-0.12.0/docs/editors-integration.md 
new/zk-0.13.0/docs/editors-integration.md
--- old/zk-0.12.0/docs/editors-integration.md   2022-12-04 10:12:48.000000000 
+0100
+++ new/zk-0.13.0/docs/editors-integration.md   2023-02-13 08:23:21.000000000 
+0100
@@ -150,19 +150,21 @@
 1. A path to any file or directory in the notebook, to locate it.
 2. <details><summary>(Optional) A dictionary of additional options (click to 
expand)</summary>
     
-    | Key                    | Type                 | Description              
                                                                 |
-    
|------------------------|----------------------|-------------------------------------------------------------------------------------------|
-    | `title`                | string               | Title of the new note    
                                                                 |
-    | `content`              | string               | Initial content of the 
note                                                               |
-    | `dir`                  | string               | Parent directory, 
relative to the root of the notebook                                    |
-    | `group`                | string               | [Note configuration 
group](config-group.md)                                               |
-    | `template`             | string               | [Custom template used to 
render the note](template-creation.md)                           |
-    | `extra`                | dictionary           | A dictionary of extra 
variables to expand in the template                                 |
-    | `date`                 | string               | A date of creation for 
the note in natural language, e.g. "tomorrow"                      |
-    | `edit`                 | boolean              | When true, the editor 
will open the newly created note (**not supported by all editors**) |
-    | `insertLinkAtLocation` | location<sup>1</sup> | A location in another 
note where a link to the new note will be inserted                  |
+    | Key                       | Type                 | Description           
                                                                                
               |
+    
|---------------------------|----------------------|----------------------------------------------------------------------------------------------------------------------|
+    | `title`                   | string               | Title of the new note 
                                                                                
               |
+    | `content`                 | string               | Initial content of 
the note                                                                        
                  |
+    | `dir`                     | string               | Parent directory, 
relative to the root of the notebook                                            
                   |
+    | `group`                   | string               | [Note configuration 
group](config-group.md)                                                         
                 |
+    | `template`                | string               | [Custom template used 
to render the note](template-creation.md)                                       
               |
+    | `extra`                   | dictionary           | A dictionary of extra 
variables to expand in the template                                             
               |
+    | `date`                    | string               | A date of creation 
for the note in natural language, e.g. "tomorrow"                               
                  |
+    | `edit`                    | boolean              | When true, the editor 
will open the newly created note (**not supported by all editors**)             
               |
+    | `dryRun`                  | boolean              | When true, `zk` will 
not actually create the note on the file system, but will return its generated 
content and path |
+    | `insertLinkAtLocation`    | location<sup>1</sup> | A location in another 
note where a link to the new note will be inserted                              
               |
+    | `insertContentAtLocation` | location<sup>1</sup> | A location in another 
note where the content of the new note will be inserted                         
               |
 
-    The `location` type is an [LSP Location 
object](https://microsoft.github.io/language-server-protocol/specification#location),
 for example:
+    1. The `location` type is an [LSP Location 
object](https://microsoft.github.io/language-server-protocol/specification#location),
 for example:
 
     ```json
     {
@@ -175,7 +177,22 @@
     ```
     </details>
 
-`zk.new` returns a dictionary with the key `path` containing the absolute path 
to the newly created file.
+`zk.new` returns a dictionary with two properties:
+
+* `path` containing the absolute path to the created note.
+* `content` containing the raw content of the created note.
+
+#### `zk.link`
+
+This LSP command allows editors to tap into the note linking mechanism. It 
takes three arguments:
+
+1. A `path` to any file in the notebook that will be linked to
+2. An LSP `location` object that points to where the link will be inserted
+3. An optional title of the link. If `title` is not provided, the title of the 
note will be inserted instead
+
+`zk.link` returns a JSON object with the path to the linked note, if the 
linking was successful.
+
+**Note**: This command is _not_ exposed in the command line. This command is 
targeted at editor / plugin authors to extend zk functionality.
 
 #### `zk.list`
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/zk-0.12.0/docs/neuron.md new/zk-0.13.0/docs/neuron.md
--- old/zk-0.12.0/docs/neuron.md        2022-12-04 10:12:48.000000000 +0100
+++ new/zk-0.13.0/docs/neuron.md        2023-02-13 08:23:21.000000000 +0100
@@ -30,4 +30,4 @@
 
 ## Emanote
 
-Emanote is neuron's successor. For Emanote-specific configuration, see 
https://emanote.srid.ca/resources/zk.
+Emanote is neuron's successor. For Emanote-specific configuration, see 
https://emanote.srid.ca/start/resources/zk.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/zk-0.12.0/internal/adapter/lsp/cmd_link.go 
new/zk-0.13.0/internal/adapter/lsp/cmd_link.go
--- old/zk-0.12.0/internal/adapter/lsp/cmd_link.go      1970-01-01 
01:00:00.000000000 +0100
+++ new/zk-0.13.0/internal/adapter/lsp/cmd_link.go      2023-02-13 
08:23:21.000000000 +0100
@@ -0,0 +1,64 @@
+package lsp
+
+import (
+       "fmt"
+       "path/filepath"
+
+       "github.com/mickael-menu/zk/internal/core"
+       "github.com/mickael-menu/zk/internal/util/errors"
+       "github.com/tliron/glsp"
+       protocol "github.com/tliron/glsp/protocol_3_16"
+)
+
+const cmdLink = "zk.link"
+
+type cmdLinkOpts struct {
+       Path     *string            `json:"path"`
+       Location *protocol.Location `json:"location"`
+       Title    *string            `json:"title"`
+}
+
+func executeCommandLink(notebook *core.Notebook, documents *documentStore, 
context *glsp.Context, args []interface{}) (interface{}, error) {
+       var opts cmdLinkOpts
+
+       if len(args) > 1 {
+               arg, ok := args[1].(map[string]interface{})
+               if !ok {
+                       return nil, fmt.Errorf("%s expects a dictionary of 
options as second argument, got: %v", cmdLink, args[1])
+               }
+               err := unmarshalJSON(arg, &opts)
+               if err != nil {
+                       return nil, errors.Wrapf(err, "failed to parse %s args, 
got: %v", cmdLink, arg)
+               }
+       }
+
+       if opts.Path == nil {
+               return nil, errors.New("'path' not provided")
+       }
+
+       note, err := notebook.FindByHref(*opts.Path, false)
+
+       if err != nil {
+               return nil, err
+       }
+
+       if note == nil {
+               return nil, errors.New("Requested note to link to not found!")
+       }
+
+       info := &linkInfo{
+               note:     note,
+               location: opts.Location,
+               title:    opts.Title,
+       }
+
+    err = linkNote(notebook, documents, context, info)
+
+    if err != nil {
+        return nil, err
+    }
+
+       return map[string]interface{}{
+               "path": filepath.Join(notebook.Path, note.Path),
+       }, nil
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/zk-0.12.0/internal/adapter/lsp/cmd_new.go 
new/zk-0.13.0/internal/adapter/lsp/cmd_new.go
--- old/zk-0.12.0/internal/adapter/lsp/cmd_new.go       2022-12-04 
10:12:48.000000000 +0100
+++ new/zk-0.13.0/internal/adapter/lsp/cmd_new.go       2023-02-13 
08:23:21.000000000 +0100
@@ -15,15 +15,17 @@
 const cmdNew = "zk.new"
 
 type cmdNewOpts struct {
-       Title                string             `json:"title"`
-       Content              string             `json:"content"`
-       Dir                  string             `json:"dir"`
-       Group                string             `json:"group"`
-       Template             string             `json:"template"`
-       Extra                map[string]string  `json:"extra"`
-       Date                 string             `json:"date"`
-       Edit                 jsonBoolean        `json:"edit"`
-       InsertLinkAtLocation *protocol.Location `json:"insertLinkAtLocation"`
+       Title                   string             `json:"title"`
+       Content                 string             `json:"content"`
+       Dir                     string             `json:"dir"`
+       Group                   string             `json:"group"`
+       Template                string             `json:"template"`
+       Extra                   map[string]string  `json:"extra"`
+       Date                    string             `json:"date"`
+       Edit                    jsonBoolean        `json:"edit"`
+       DryRun                  jsonBoolean        `json:"dryRun"`
+       InsertLinkAtLocation    *protocol.Location `json:"insertLinkAtLocation"`
+       InsertContentAtLocation *protocol.Location 
`json:"insertContentAtLocation"`
 }
 
 func executeCommandNew(notebook *core.Notebook, documents *documentStore, 
context *glsp.Context, args []interface{}) (interface{}, error) {
@@ -51,6 +53,7 @@
                Group:     opt.NewNotEmptyString(opts.Group),
                Template:  opt.NewNotEmptyString(opts.Template),
                Extra:     opts.Extra,
+               DryRun:    bool(opts.DryRun),
                Date:      date,
        })
        if err != nil {
@@ -69,47 +72,41 @@
                return nil, errors.New("zk.new could not generate a new note")
        }
 
-       if opts.InsertLinkAtLocation != nil {
-               doc, ok := documents.Get(opts.InsertLinkAtLocation.URI)
-               if !ok {
-                       return nil, fmt.Errorf("can't insert link in %s", 
opts.InsertLinkAtLocation.URI)
-               }
-               linkFormatter, err := notebook.NewLinkFormatter()
-               if err != nil {
-                       return nil, err
-               }
-
-               path := core.NotebookPath{
-                       Path:       note.Path,
-                       BasePath:   notebook.Path,
-                       WorkingDir: filepath.Dir(doc.Path),
-               }
-               linkFormatterContext, err := core.NewLinkFormatterContext(path, 
note.Title, note.Metadata)
-               if err != nil {
-                       return nil, err
-               }
-
-               link, err := linkFormatter(linkFormatterContext)
-               if err != nil {
-                       return nil, err
-               }
-
+       if opts.InsertContentAtLocation != nil {
                go context.Call(protocol.ServerWorkspaceApplyEdit, 
protocol.ApplyWorkspaceEditParams{
                        Edit: protocol.WorkspaceEdit{
                                Changes: map[string][]protocol.TextEdit{
-                                       opts.InsertLinkAtLocation.URI: {{Range: 
opts.InsertLinkAtLocation.Range, NewText: link}},
+                                       opts.InsertContentAtLocation.URI: 
{{Range: opts.InsertContentAtLocation.Range, NewText: note.RawContent}},
                                },
                        },
                }, nil)
        }
 
+       if !opts.DryRun && opts.InsertLinkAtLocation != nil {
+        minNote := note.AsMinimalNote()
+
+        info := &linkInfo{
+            note: &minNote,
+            location: opts.InsertLinkAtLocation,
+            title: &opts.Title,
+        }
+        err := linkNote(notebook, documents, context, info)
+
+        if err != nil {
+            return nil, err
+        }
+       }
+
        absPath := filepath.Join(notebook.Path, note.Path)
-       if opts.Edit {
+       if !opts.DryRun && opts.Edit {
                go context.Call(protocol.ServerWindowShowDocument, 
protocol.ShowDocumentParams{
                        URI:       pathToURI(absPath),
                        TakeFocus: boolPtr(true),
                }, nil)
        }
 
-       return map[string]interface{}{"path": absPath}, nil
+       return map[string]interface{}{
+               "path":    absPath,
+               "content": note.RawContent,
+       }, nil
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/zk-0.12.0/internal/adapter/lsp/server.go 
new/zk-0.13.0/internal/adapter/lsp/server.go
--- old/zk-0.12.0/internal/adapter/lsp/server.go        2022-12-04 
10:12:48.000000000 +0100
+++ new/zk-0.13.0/internal/adapter/lsp/server.go        2023-02-13 
08:23:21.000000000 +0100
@@ -369,6 +369,13 @@
                        }
                        return executeCommandNew(nb, server.documents, context, 
params.Arguments)
 
+               case cmdLink:
+                       nb, err := openNotebook()
+                       if err != nil {
+                               return nil, err
+                       }
+                       return executeCommandLink(nb, server.documents, 
context, params.Arguments)
+
                case cmdList:
                        nb, err := openNotebook()
                        if err != nil {
@@ -421,6 +428,7 @@
                                Title: actionTitle,
                                Kind:  
stringPtr(protocol.CodeActionKindRefactor),
                                Command: &protocol.Command{
+                                       Title:     actionTitle,
                                        Command:   cmdNew,
                                        Arguments: []interface{}{wd, jsonOpts},
                                },
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/zk-0.12.0/internal/adapter/lsp/util.go 
new/zk-0.13.0/internal/adapter/lsp/util.go
--- old/zk-0.12.0/internal/adapter/lsp/util.go  2022-12-04 10:12:48.000000000 
+0100
+++ new/zk-0.13.0/internal/adapter/lsp/util.go  2023-02-13 08:23:21.000000000 
+0100
@@ -3,10 +3,14 @@
 import (
        "fmt"
        "net/url"
+       "path/filepath"
        "runtime"
        "strings"
 
+       "github.com/mickael-menu/zk/internal/core"
        "github.com/mickael-menu/zk/internal/util/errors"
+       "github.com/tliron/glsp"
+       protocol "github.com/tliron/glsp/protocol_3_16"
 )
 
 func pathToURI(path string) string {
@@ -56,3 +60,59 @@
        }
        return nil
 }
+
+type linkInfo struct {
+    note *core.MinimalNote
+       location *protocol.Location
+       title    *string
+}
+
+func linkNote(notebook *core.Notebook, documents *documentStore, context 
*glsp.Context, info *linkInfo) error {
+       if info.location == nil {
+               return errors.New("'location' not provided")
+       }
+
+       // Get current document to edit
+       doc, ok := documents.Get(info.location.URI)
+       if !ok {
+               return fmt.Errorf("Cannot insert link in '%s'", 
info.location.URI)
+       }
+
+       formatter, err := notebook.NewLinkFormatter()
+       if err != nil {
+               return err
+       }
+
+       path := core.NotebookPath{
+               Path:       info.note.Path,
+               BasePath:   notebook.Path,
+               WorkingDir: filepath.Dir(doc.Path),
+       }
+
+       var title *string
+       title = info.title
+
+       if title == nil {
+               title = &info.note.Title
+       }
+
+       formatterContext, err := core.NewLinkFormatterContext(path, *title, 
info.note.Metadata)
+       if err != nil {
+               return err
+       }
+
+       link, err := formatter(formatterContext)
+       if err != nil {
+               return err
+       }
+
+       go context.Call(protocol.ServerWorkspaceApplyEdit, 
protocol.ApplyWorkspaceEditParams{
+               Edit: protocol.WorkspaceEdit{
+                       Changes: map[string][]protocol.TextEdit{
+                               info.location.URI: {{Range: 
info.location.Range, NewText: link}},
+                       },
+               },
+       }, nil)
+
+       return nil
+}

Reply via email to