Skip to content

Commit

Permalink
Avoid crash when new directory created in project root (#8199)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vitvakatu authored Nov 1, 2023
1 parent 3fd2249 commit f37ec96
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/gui2/ydoc-server/languageServerSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,18 @@ export class LanguageServerSession extends ObservableV2<Events> {
}
})

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()
Expand Down Expand Up @@ -180,6 +185,10 @@ export class LanguageServerSession extends ObservableV2<Events> {
}
}

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('/')
Expand Down

0 comments on commit f37ec96

Please sign in to comment.