-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathBuiltinExtensionWorkspacePlugin.swift
More file actions
78 lines (68 loc) · 2.51 KB
/
BuiltinExtensionWorkspacePlugin.swift
File metadata and controls
78 lines (68 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import Foundation
import Workspace
import LanguageServerProtocol
public final class BuiltinExtensionWorkspacePlugin: WorkspacePlugin {
let extensionManager: BuiltinExtensionManager
public init(workspace: Workspace, extensionManager: BuiltinExtensionManager = .shared) {
self.extensionManager = extensionManager
super.init(workspace: workspace)
}
override public func didOpenFilespace(_ filespace: Filespace) async {
await notifyOpenFile(filespace: filespace)
}
override public func didSaveFilespace(_ filespace: Filespace) {
notifySaveFile(filespace: filespace)
}
override public func didUpdateFilespace(
_ filespace: Filespace,
content: String,
contentChanges: [TextDocumentContentChangeEvent]? = nil
) async {
await notifyUpdateFile(filespace: filespace, content: content, contentChanges: contentChanges)
}
override public func didCloseFilespace(_ fileURL: URL) {
Task {
for ext in extensionManager.extensions {
ext.workspace(
.init(workspaceURL: workspaceURL, projectURL: projectRootURL),
didCloseDocumentAt: fileURL
)
}
}
}
public func notifyOpenFile(filespace: Filespace) async {
guard filespace.isTextReadable else { return }
for ext in extensionManager.extensions {
await ext.workspace(
.init(workspaceURL: workspaceURL, projectURL: projectRootURL),
didOpenDocumentAt: filespace.fileURL
)
}
}
public func notifyUpdateFile(
filespace: Filespace,
content: String,
contentChanges: [TextDocumentContentChangeEvent]? = nil
) async {
guard filespace.isTextReadable else { return }
for ext in extensionManager.extensions {
await ext.workspace(
.init(workspaceURL: workspaceURL, projectURL: projectRootURL),
didUpdateDocumentAt: filespace.fileURL,
content: content,
contentChanges: contentChanges
)
}
}
public func notifySaveFile(filespace: Filespace) {
Task {
guard filespace.isTextReadable else { return }
for ext in extensionManager.extensions {
ext.workspace(
.init(workspaceURL: workspaceURL, projectURL: projectRootURL),
didSaveDocumentAt: filespace.fileURL
)
}
}
}
}