forked from ufo5260987423/scheme-langserver
-
Notifications
You must be signed in to change notification settings - Fork 2
add:did-create/rename/delete #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,18 +15,22 @@ | |||||||||||||||||||||||||||||||||||||||||||
| workspace-library-node | ||||||||||||||||||||||||||||||||||||||||||||
| workspace-library-node-set! | ||||||||||||||||||||||||||||||||||||||||||||
| workspace-file-linkage | ||||||||||||||||||||||||||||||||||||||||||||
| workspace-facet | ||||||||||||||||||||||||||||||||||||||||||||
| workspace-type-inference? | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| update-file-node-with-tail | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| attach-new-file | ||||||||||||||||||||||||||||||||||||||||||||
| remove-new-file | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| pick | ||||||||||||||||||||||||||||||||||||||||||||
| generate-library-node) | ||||||||||||||||||||||||||||||||||||||||||||
| (import | ||||||||||||||||||||||||||||||||||||||||||||
| (ufo-match) | ||||||||||||||||||||||||||||||||||||||||||||
| (ufo-threaded-function) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| (chezscheme) | ||||||||||||||||||||||||||||||||||||||||||||
| (only (srfi :13 strings) string-suffix?) | ||||||||||||||||||||||||||||||||||||||||||||
| (only (srfi :13 strings) string-suffix? string-prefix?) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| (scheme-langserver util path) | ||||||||||||||||||||||||||||||||||||||||||||
| (ufo-try) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -85,18 +89,17 @@ | |||||||||||||||||||||||||||||||||||||||||||
| [(path identifier threaded? type-inference?) (init-workspace path identifier 'r6rs threaded? type-inference?)] | ||||||||||||||||||||||||||||||||||||||||||||
| [(path identifier top-environment threaded? type-inference?) | ||||||||||||||||||||||||||||||||||||||||||||
| ;; (pretty-print `(DEBUG: function: init-workspace)) | ||||||||||||||||||||||||||||||||||||||||||||
| (let* ([root-file-node | ||||||||||||||||||||||||||||||||||||||||||||
| (init-virtual-file-system path '() | ||||||||||||||||||||||||||||||||||||||||||||
| (cond | ||||||||||||||||||||||||||||||||||||||||||||
| ;todo:add more filter | ||||||||||||||||||||||||||||||||||||||||||||
| [(equal? 'r7rs top-environment) (generate-txt-file-filter (string-append path "/tests/r7rs"))] | ||||||||||||||||||||||||||||||||||||||||||||
| [(equal? 'akku identifier) (generate-akku-acceptable-file-filter (string-append path "/.akku/list"))] | ||||||||||||||||||||||||||||||||||||||||||||
| [else (generate-akku-acceptable-file-filter (string-append path "/.akku/list"))]))] | ||||||||||||||||||||||||||||||||||||||||||||
| (let* ([facet | ||||||||||||||||||||||||||||||||||||||||||||
| (case identifier | ||||||||||||||||||||||||||||||||||||||||||||
| [txt (generate-txt-file-filter)] | ||||||||||||||||||||||||||||||||||||||||||||
| [akku (generate-akku-acceptable-file-filter (string-append path "/.akku/list"))] | ||||||||||||||||||||||||||||||||||||||||||||
| [else (generate-akku-acceptable-file-filter (string-append path "/.akku/list"))])] | ||||||||||||||||||||||||||||||||||||||||||||
| [root-file-node (init-virtual-file-system path '() facet)] | ||||||||||||||||||||||||||||||||||||||||||||
| [root-library-node (init-library-node root-file-node)] | ||||||||||||||||||||||||||||||||||||||||||||
| [file-linkage (init-file-linkage root-file-node root-library-node)] | ||||||||||||||||||||||||||||||||||||||||||||
| [batches (get-init-reference-batches file-linkage)]) | ||||||||||||||||||||||||||||||||||||||||||||
| (init-references root-file-node root-library-node file-linkage threaded? batches type-inference?) | ||||||||||||||||||||||||||||||||||||||||||||
| (make-workspace root-file-node root-library-node file-linkage identifier threaded? type-inference?))])) | ||||||||||||||||||||||||||||||||||||||||||||
| (make-workspace root-file-node root-library-node file-linkage facet threaded? type-inference?))])) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ;; head -[linkage]->files | ||||||||||||||||||||||||||||||||||||||||||||
| ;; for single file | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -206,12 +209,15 @@ | |||||||||||||||||||||||||||||||||||||||||||
| (let* ([linkage (workspace-file-linkage workspace-instance)] | ||||||||||||||||||||||||||||||||||||||||||||
| [root-file-node (workspace-file-node workspace-instance)] | ||||||||||||||||||||||||||||||||||||||||||||
| [root-library-node (workspace-library-node workspace-instance)] | ||||||||||||||||||||||||||||||||||||||||||||
| [library-identifiers-list (get-library-identifiers-list (file-node-document target-file-node))] | ||||||||||||||||||||||||||||||||||||||||||||
| [path (refresh-file-linkage&get-refresh-path linkage root-library-node target-file-node (document-index-node-list (file-node-document target-file-node)) library-identifiers-list)] | ||||||||||||||||||||||||||||||||||||||||||||
| [path-aheadof `(,@(list-ahead-of path (file-node-path target-file-node)) ,(file-node-path target-file-node))] | ||||||||||||||||||||||||||||||||||||||||||||
| [refreshable-path (filter (lambda (single) (document-refreshable? (file-node-document (walk-file root-file-node single)))) path-aheadof)] | ||||||||||||||||||||||||||||||||||||||||||||
| [refreshable-batches (shrink-paths linkage refreshable-path)]) | ||||||||||||||||||||||||||||||||||||||||||||
| (init-references workspace-instance refreshable-batches)))) | ||||||||||||||||||||||||||||||||||||||||||||
| [library-identifiers-list (get-library-identifiers-list (file-node-document target-file-node))]) | ||||||||||||||||||||||||||||||||||||||||||||
| (if (null? library-identifiers-list) | ||||||||||||||||||||||||||||||||||||||||||||
| (init-references workspace-instance `((,(file-node-path target-file-node)))) | ||||||||||||||||||||||||||||||||||||||||||||
| (let* ([path (refresh-file-linkage&get-refresh-path linkage root-library-node target-file-node (document-index-node-list (file-node-document target-file-node)) library-identifiers-list)] | ||||||||||||||||||||||||||||||||||||||||||||
| [path-aheadof `(,@(list-ahead-of path (file-node-path target-file-node)) ,(file-node-path target-file-node))] | ||||||||||||||||||||||||||||||||||||||||||||
| [refreshable-path (filter (lambda (single) (document-refreshable? (file-node-document (walk-file root-file-node single)))) path-aheadof)] | ||||||||||||||||||||||||||||||||||||||||||||
| ;target-file-node may don't have library-identifiers-list | ||||||||||||||||||||||||||||||||||||||||||||
| [refreshable-batches (shrink-paths linkage refreshable-path)]) | ||||||||||||||||||||||||||||||||||||||||||||
| (init-references workspace-instance refreshable-batches)))))) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| (define (init-virtual-file-system path parent my-filter) | ||||||||||||||||||||||||||||||||||||||||||||
| (if (my-filter path) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -227,32 +233,79 @@ | |||||||||||||||||||||||||||||||||||||||||||
| (lambda (p) | ||||||||||||||||||||||||||||||||||||||||||||
| (init-virtual-file-system | ||||||||||||||||||||||||||||||||||||||||||||
| (string-append path | ||||||||||||||||||||||||||||||||||||||||||||
| (if (string-suffix? (list->string (list (directory-separator))) path) | ||||||||||||||||||||||||||||||||||||||||||||
| (if (string-suffix? (string (directory-separator)) path) | ||||||||||||||||||||||||||||||||||||||||||||
| "" | ||||||||||||||||||||||||||||||||||||||||||||
| (list->string (list (directory-separator)))) | ||||||||||||||||||||||||||||||||||||||||||||
| (string (directory-separator))) | ||||||||||||||||||||||||||||||||||||||||||||
| p) | ||||||||||||||||||||||||||||||||||||||||||||
| node | ||||||||||||||||||||||||||||||||||||||||||||
| my-filter)) | ||||||||||||||||||||||||||||||||||||||||||||
| (directory-list path)) | ||||||||||||||||||||||||||||||||||||||||||||
| '())]) | ||||||||||||||||||||||||||||||||||||||||||||
| (file-node-children-set! node (filter (lambda(p) (not (null? p))) children)) | ||||||||||||||||||||||||||||||||||||||||||||
| (file-node-children-set! node (filter (lambda (p) (not (null? p))) children)) | ||||||||||||||||||||||||||||||||||||||||||||
| node) | ||||||||||||||||||||||||||||||||||||||||||||
| '())) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| (define (remove-new-file path parent my-filter) | ||||||||||||||||||||||||||||||||||||||||||||
| (let ([f (walk-file parent path)]) | ||||||||||||||||||||||||||||||||||||||||||||
| (cond | ||||||||||||||||||||||||||||||||||||||||||||
| [(not (null? f)) '()] | ||||||||||||||||||||||||||||||||||||||||||||
| [else | ||||||||||||||||||||||||||||||||||||||||||||
| (file-node-children-set! | ||||||||||||||||||||||||||||||||||||||||||||
| (file-node-parent f) | ||||||||||||||||||||||||||||||||||||||||||||
| (filter | ||||||||||||||||||||||||||||||||||||||||||||
| (lambda (x) (not (equal? x f))) | ||||||||||||||||||||||||||||||||||||||||||||
| (file-node-children (file-node-parent f))))]))) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| (define (attach-new-file path parent my-filter) | ||||||||||||||||||||||||||||||||||||||||||||
| (let ([f (walk-file parent path)]) | ||||||||||||||||||||||||||||||||||||||||||||
| (cond | ||||||||||||||||||||||||||||||||||||||||||||
| [(not (my-filter path)) '()] | ||||||||||||||||||||||||||||||||||||||||||||
| [(not (file-exists? path)) '()] | ||||||||||||||||||||||||||||||||||||||||||||
| [(not (null? f)) f] | ||||||||||||||||||||||||||||||||||||||||||||
| [(file-node-folder? parent) | ||||||||||||||||||||||||||||||||||||||||||||
| (let ([maybe-parent | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+249
to
+267
|
||||||||||||||||||||||||||||||||||||||||||||
| (define (remove-new-file path parent my-filter) | |
| (let ([f (walk-file parent path)]) | |
| (cond | |
| [(not (null? f)) '()] | |
| [else | |
| (file-node-children-set! | |
| (file-node-parent f) | |
| (filter | |
| (lambda (x) (not (equal? x f))) | |
| (file-node-children (file-node-parent f))))]))) | |
| (define (attach-new-file path parent my-filter) | |
| (let ([f (walk-file parent path)]) | |
| (cond | |
| [(not (my-filter path)) '()] | |
| [(not (file-exists? path)) '()] | |
| [(not (null? f)) f] | |
| [(file-node-folder? parent) | |
| (let ([maybe-parent | |
| ;; Logic from `remove-new-file` integrated into `did-delete` function. | |
| ;; Remove the `remove-new-file` function entirely. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| (library (scheme-langserver protocol apis file-change-notification) | ||
| (export | ||
| did-create | ||
| did-delete | ||
| did-rename) | ||
| (import | ||
| (chezscheme) | ||
|
|
||
| (scheme-langserver analysis workspace) | ||
| (scheme-langserver analysis identifier reference) | ||
|
|
||
| (scheme-langserver protocol alist-access-object) | ||
|
|
||
| (scheme-langserver util association) | ||
| (scheme-langserver util path) | ||
| (ufo-try) | ||
| (scheme-langserver util text) | ||
| (scheme-langserver util io) | ||
|
|
||
| (scheme-langserver virtual-file-system index-node) | ||
| (scheme-langserver virtual-file-system document) | ||
| (scheme-langserver virtual-file-system file-node) | ||
|
|
||
| (scheme-langserver analysis package-manager akku) | ||
| (scheme-langserver analysis package-manager txt-filter) | ||
|
|
||
| (only (srfi :13 strings) string-replace)) | ||
|
|
||
| ; https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didCreateFiles | ||
| (define (did-create workspace params) | ||
| (let* ([files (vector->list (assq-ref params 'files))] | ||
| [uris (map (lambda (file) (assq-ref file 'uri)) files)] | ||
| [paths (map uri->path uris)] | ||
| [facet (workspace-facet workspace)] | ||
| [root-file-node (workspace-file-node workspace)]) | ||
| (map | ||
| (lambda (file-node) | ||
| (refresh-workspace-for workspace file-node)) | ||
| (map | ||
| (lambda (path) (attach-new-file path root-file-node facet)) | ||
| paths)))) | ||
|
|
||
| ; https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didRenameFiles | ||
| (define (did-rename workspace params) | ||
| (map | ||
| (lambda (file) | ||
| (let* ([old (assq-ref file 'oldUri)] | ||
| [old-path (uri->path old)] | ||
| [old-file-node (walk-file (workspace-file-node workspace) old-path)] | ||
| [new (assq-ref file 'newUri)] | ||
| [new-path (uri->path new)] | ||
| [root-file-node (workspace-file-node workspace)] | ||
| [facet (workspace-facet workspace)] | ||
| [new-file-node (attach-new-file new-path root-file-node facet)]) | ||
| (file-node-document-set! new-file-node (file-node-document old-file-node)))) | ||
| (vector->list (assq-ref params 'files)))) | ||
|
|
||
| ;https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didDeleteFiles | ||
| (define (did-delete workspace params) | ||
| (let* ([files (vector->list (assq-ref params 'files))] | ||
| [uris (map (lambda (file) (assq-ref file 'uri)) files)] | ||
| [paths (map uri->path uris)]) | ||
| (map | ||
| (lambda (file-node) | ||
| (if (file-node? file-node) | ||
| (file-node-children-set! | ||
| (file-node-parent file-node) | ||
| (filter | ||
| (lambda (siblins) | ||
| (not (equal? file-node siblins))) | ||
| (file-node-children (file-node-parent file-node)))))) | ||
| (map | ||
| (lambda (path) (walk-file (workspace-file-node workspace) path)) | ||
| paths)))) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The early-return condition in remove-new-file is inverted: it currently returns immediately when
fis found and only removes children whenfis absent. Swap the branches so that whenfis null you return, otherwise proceed to remove the node.