Skip to content

Commit

Permalink
🚚 Moved FsWatcher to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
SPGoding committed Oct 12, 2024
1 parent 0554bc0 commit 23af981
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 34 deletions.
8 changes: 1 addition & 7 deletions packages/core/src/common/externals/BrowserExternals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import type {
ExternalDownloaderOptions,
RemoteUriString,
} from './downloader.js'
import type {
ExternalEventEmitter,
ExternalFileSystem,
Externals,
FsLocation,
FsWatcher,
} from './index.js'
import type { ExternalEventEmitter, ExternalFileSystem, Externals, FsLocation } from './index.js'

type Listener = (...args: unknown[]) => unknown
class BrowserEventEmitter implements ExternalEventEmitter {
Expand Down
26 changes: 0 additions & 26 deletions packages/core/src/common/externals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,3 @@ export interface ExternalFileSystem {
* A file URI string or a URI object.
*/
export type FsLocation = string | Uri

/**
* A file system watcher that reports additions, changes, and deletions of files.
* Changes to directories should not be reported.
*/
export interface FsWatcher {
get isReady(): boolean
get watchedFiles(): Set<string>

on(eventName: 'ready', listener: () => unknown): this
once(eventName: 'ready', listener: () => unknown): this

on(eventName: 'add', listener: (uri: string) => unknown): this
once(eventName: 'add', listener: (uri: string) => unknown): this

on(eventName: 'change', listener: (uri: string) => unknown): this
once(eventName: 'change', listener: (uri: string) => unknown): this

on(eventName: 'unlink', listener: (uri: string) => unknown): this
once(eventName: 'unlink', listener: (uri: string) => unknown): this

on(eventName: 'error', listener: (error: Error) => unknown): this
once(eventName: 'error', listener: (error: Error) => unknown): this

close(): Promise<void>
}
25 changes: 25 additions & 0 deletions packages/core/src/service/FsWatcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* A file system watcher that reports additions, changes, and deletions of files.
* Changes to directories should not be reported.
*/
export interface FsWatcher {
get isReady(): boolean
get watchedFiles(): Set<string>

on(eventName: 'ready', listener: () => unknown): this
once(eventName: 'ready', listener: () => unknown): this

on(eventName: 'add', listener: (uri: string) => unknown): this
once(eventName: 'add', listener: (uri: string) => unknown): this

on(eventName: 'change', listener: (uri: string) => unknown): this
once(eventName: 'change', listener: (uri: string) => unknown): this

on(eventName: 'unlink', listener: (uri: string) => unknown): this
once(eventName: 'unlink', listener: (uri: string) => unknown): this

on(eventName: 'error', listener: (error: Error) => unknown): this
once(eventName: 'error', listener: (error: Error) => unknown): this

close(): Promise<void>
}
3 changes: 2 additions & 1 deletion packages/core/src/service/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Ignore } from 'ignore'
import ignore from 'ignore'
import type { TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument'
import { TextDocument } from 'vscode-languageserver-textdocument'
import type { ExternalEventEmitter, Externals, FsWatcher, IntervalId } from '../common/index.js'
import type { ExternalEventEmitter, Externals, IntervalId } from '../common/index.js'
import {
bufferToString,
Logger,
Expand Down Expand Up @@ -34,6 +34,7 @@ import { LinterErrorReporter } from './ErrorReporter.js'
import { ArchiveUriSupporter, FileService, FileUriSupporter } from './FileService.js'
import type { RootUriString } from './fileUtil.js'
import { fileUtil } from './fileUtil.js'
import type { FsWatcher } from './FsWatcher.js'
import { MetaRegistry } from './MetaRegistry.js'
import { ProfilerFactory } from './Profiler.js'

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './Downloader.js'
export * from './ErrorReporter.js'
export { FileService, UriProtocolSupporter } from './FileService.js'
export * from './fileUtil.js'
export * from './FsWatcher.js'
export * from './Hover.js'
export * from './MetaRegistry.js'
export * from './Profiler.js'
Expand Down

0 comments on commit 23af981

Please sign in to comment.