Skip to content

Commit 8ff20f0

Browse files
committed
fix: workspace
1 parent f2f2cc7 commit 8ff20f0

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

src/cm/lsp/workspace.ts

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,6 @@ export default class AcodeWorkspace extends Workspace {
113113
return "plaintext";
114114
}
115115

116-
#getOpenFileCallback(): ((uri: string) => Promise<EditorView | null>) | null {
117-
if (typeof this.options.openFile === "function") {
118-
return this.options.openFile;
119-
}
120-
if (typeof this.options.displayFile === "function") {
121-
return this.options.displayFile;
122-
}
123-
return null;
124-
}
125-
126116
syncFiles(): readonly WorkspaceFileUpdate[] {
127117
const updates: WorkspaceFileUpdate[] = [];
128118
for (const file of this.files) {
@@ -164,22 +154,8 @@ export default class AcodeWorkspace extends Workspace {
164154
return this.#getFileEntry(uri);
165155
}
166156

167-
async requestFile(uri: string): Promise<AcodeWorkspaceFile | null> {
168-
const existing = this.#getFileEntry(uri);
169-
if (existing) return existing;
170-
171-
const openFileCallback = this.#getOpenFileCallback();
172-
if (!openFileCallback) return null;
173-
174-
try {
175-
const view = await openFileCallback(uri);
176-
if (!view?.state?.doc) return null;
177-
const languageId = this.#resolveLanguageIdForUri(uri);
178-
return this.#getOrCreateFile(uri, languageId, view);
179-
} catch (error) {
180-
console.error(`[LSP:Workspace] Failed to open file: ${uri}`, error);
181-
return null;
182-
}
157+
requestFile(uri: string): Promise<AcodeWorkspaceFile | null> {
158+
return Promise.resolve(this.#getFileEntry(uri));
183159
}
184160

185161
connected(): void {
@@ -209,16 +185,16 @@ export default class AcodeWorkspace extends Workspace {
209185
uri: string,
210186
update: TransactionSpec,
211187
): Promise<void> {
212-
const openFileCallback = this.#getOpenFileCallback();
213-
if (!openFileCallback) return;
188+
if (typeof this.options.displayFile !== "function") return;
214189

215190
try {
216-
const file = await this.requestFile(uri);
217-
if (!file) return;
218-
219-
const view = file.getView();
220-
if (view) {
221-
view.dispatch(update);
191+
const view = await this.options.displayFile(uri);
192+
if (!view?.state?.doc) return;
193+
const languageId = this.#resolveLanguageIdForUri(uri);
194+
const file = this.#getOrCreateFile(uri, languageId, view);
195+
const fileView = file.getView();
196+
if (fileView) {
197+
fileView.dispatch(update);
222198
}
223199
} catch (error) {
224200
console.error(`[LSP:Workspace] Failed to apply update: ${uri}`, error);

0 commit comments

Comments
 (0)