From f37ec961499e1e35746a60f4f977ec6a85a2ffae Mon Sep 17 00:00:00 2001 From: Ilya Bogdanov Date: Wed, 1 Nov 2023 16:22:49 +0400 Subject: [PATCH] Avoid crash when new directory created in project root (#8199) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While working on #8158, I noticed a crash when the `data` directory is created at the project root. Turns out it is the issue in the `ydoc-server`, which thinks every filesystem event is about files. Unfortunately, we don‘t have the needed info available, so we need to make the `file/info` request. --- app/gui2/ydoc-server/languageServerSession.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/gui2/ydoc-server/languageServerSession.ts b/app/gui2/ydoc-server/languageServerSession.ts index d2a6f86720a6..90e8ca745917 100644 --- a/app/gui2/ydoc-server/languageServerSession.ts +++ b/app/gui2/ydoc-server/languageServerSession.ts @@ -70,13 +70,18 @@ export class LanguageServerSession extends ObservableV2 { } }) - this.ls.on('file/event', (event) => { + this.ls.on('file/event', async (event) => { if (DEBUG_LOG_SYNC) { console.log('file/event', event) } switch (event.kind) { case 'Added': - this.getModuleModel(event.path).open() + if (isSourceFile(event.path)) { + const fileInfo = await this.ls.fileInfo(event.path) + if (fileInfo.attributes.kind.type == 'File') { + this.getModuleModel(event.path).open() + } + } break case 'Modified': this.getModuleModelIfExists(event.path)?.reload() @@ -180,6 +185,10 @@ export class LanguageServerSession extends ObservableV2 { } } +const isSourceFile = (path: Path): boolean => { + return path.segments[0] === 'src' && path.segments[path.segments.length - 1].endsWith('.enso') +} + const pathToModuleName = (path: Path): string => { if (path.segments[0] === 'src') { return path.segments.slice(1).join('/')