@@ -10,74 +10,64 @@ function workspace_didChangeWatchedFiles_notification(params::DidChangeWatchedFi
1010 uri. scheme== " file" || continue
1111
1212 if change. type == FileChangeTypes. Created || change. type == FileChangeTypes. Changed
13- text_file = JuliaWorkspaces. read_text_file_from_uri (uri)
14- if change. type == FileChangeTypes. Created
13+ text_file = nothing
14+ try
15+ JuliaWorkspaces. read_text_file_from_uri (uri)
16+ catch err
17+ if ! (is_walkdir_error (err) || err isa JuliaWorkspaces. JWInvalidFileContent)
18+ rethrow (err)
19+ end
20+ end
21+
22+ # First handle case where fild could not be found or has invalid content
23+ if text_file === nothing
1524 if haskey (server. _files_from_disc, uri)
16- error ( " This should not happen " )
25+ delete! (server . _files_from_disc, uri )
1726 end
18- server. _files_from_disc[uri] = text_file
1927
20- if ! haskey (server. _open_file_versions, uri)
21- JuliaWorkspaces. add_file ! (server. workspace, text_file )
28+ if ! haskey (server. _open_file_versions, uri) && JuliaWorkspaces . has_file (server . workspace, uri)
29+ JuliaWorkspaces. remove_file ! (server. workspace, uri )
2230 end
23- elseif change. type == FileChangeTypes. Changed
24- if ! haskey (server. _files_from_disc, uri)
25- error (" This should not happen" )
31+
32+ if hasdocument (server, uri)
33+ doc = getdocument (server, uri)
34+
35+ if ! get_open_in_editor (doc)
36+ deletedocument! (server, uri)
37+ end
2638 end
39+ else
2740 server. _files_from_disc[uri] = text_file
2841
2942 if ! haskey (server. _open_file_versions, uri)
30- JuliaWorkspaces. update_file! (server. workspace, text_file)
43+ if JuliaWorkspaces. has_file (server. workspace, uri)
44+ JuliaWorkspaces. update_file! (server. workspace, text_file)
45+ else
46+ JuliaWorkspaces. add_file! (server. workspace, text_file)
47+ end
3148 end
32- end
3349
34- if hasdocument (server, uri)
35- doc = getdocument (server, uri)
50+ if hasdocument (server, uri)
51+ doc = getdocument (server, uri)
3652
37- # Currently managed by the client, we don't do anything
38- if get_open_in_editor (doc)
39- continue
40- else
41- filepath = uri2filepath (uri)
42- content = try
43- s = read (filepath, String)
44- if ! our_isvalid (s)
45- deletedocument! (server, uri)
46- continue
47- end
48- s
49- catch err
50- isa (err, Base. IOError) || isa (err, Base. SystemError) || rethrow ()
51- deletedocument! (server, uri)
52- continue
53- end
53+ if ! get_open_in_editor (doc)
54+ set_text_document! (doc, TextDocument (uri, text_document. content. content, 0 ))
55+ set_is_workspace_file (doc, true )
5456
55- set_text_document! (doc, TextDocument (uri, content, 0 ))
56- set_is_workspace_file (doc, true )
57+ parse_all (doc, server)
58+ push! (docs_to_lint, doc)
59+ end
60+ else
61+ doc = Document (TextDocument (uri, text_document. content. content, 0 ), true , server)
62+ setdocument! (server, uri, doc)
5763
5864 parse_all (doc, server)
5965 push! (docs_to_lint, doc)
6066 end
61- else
62- filepath = uri2filepath (uri)
63- content = try
64- s = read (filepath, String)
65- our_isvalid (s) || continue
66- s
67- catch err
68- isa (err, Base. IOError) || isa (err, Base. SystemError) || rethrow ()
69- continue
70- end
71-
72- doc = Document (TextDocument (uri, content, 0 ), true , server)
73- setdocument! (server, uri, doc)
74-
75- parse_all (doc, server)
76- push! (docs_to_lint, doc)
7767 end
7868 elseif change. type == FileChangeTypes. Deleted
7969 delete! (server. _files_from_disc, uri)
80- if ! haskey (server. _open_file_versions, uri)
70+ if ! haskey (server. _open_file_versions, uri) && JuliaWorkspaces . has_file (server . workspace, uri)
8171 JuliaWorkspaces. remove_file! (server. workspace, uri)
8272 end
8373
@@ -87,13 +77,8 @@ function workspace_didChangeWatchedFiles_notification(params::DidChangeWatchedFi
8777 # We only handle if currently not managed by client
8878 if ! get_open_in_editor (doc)
8979 deletedocument! (server, uri)
90-
91- publishDiagnosticsParams = PublishDiagnosticsParams (uri, missing , Diagnostic[])
92- JSONRPC. send (conn, textDocument_publishDiagnostics_notification_type, publishDiagnosticsParams)
9380 else
94- # TODO replace with accessor function once the other PR
95- # that introduces the accessor is merged
96- doc. _workspace_file = false
81+ set_is_workspace_file (doc, false )
9782 end
9883 end
9984 else
0 commit comments