-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- define file system endpoints - clangd LS uses message port for communication - Use wtm new ComChannelEndpoints for handling async communication of message channels or workers - worker transfers files to client via message channel - clangd example: list open files below editor - Prototype: File system related code added to monaco-languageclient/fs
- Loading branch information
Showing
26 changed files
with
7,375 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2024 TypeFox and others. | ||
* Licensed under the MIT License. See LICENSE in the package root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
import { Logger } from 'monaco-languageclient/tools'; | ||
|
||
export interface FileReadRequest { | ||
resourceUri: string | ||
} | ||
|
||
export type FileReadResultStatus = 'success' | 'denied'; | ||
|
||
export interface FileReadRequestResult { | ||
status: FileReadResultStatus | ||
content: string | ArrayBuffer | ||
} | ||
|
||
export interface FileUpdate { | ||
resourceUri: string | ||
content: string | ArrayBuffer | ||
} | ||
|
||
export type FileUpdateResultStatus = 'equal' | 'updated' | 'created' | 'denied'; | ||
|
||
export interface FileUpdateResult { | ||
status: FileUpdateResultStatus | ||
message?: string | ||
} | ||
|
||
export interface DirectoryListingRequest { | ||
directoryUri: string | ||
} | ||
|
||
export interface DirectoryListingRequestResult { | ||
files: string[] | ||
} | ||
|
||
export type StatsRequestType = 'directory' | 'file'; | ||
|
||
export interface StatsRequest { | ||
type: StatsRequestType, | ||
resourceUri: string | ||
} | ||
|
||
export interface StatsRequestResult { | ||
type: StatsRequestType | ||
size: number | ||
name: string | ||
mtime: number | ||
} | ||
|
||
export enum EndpointType { | ||
DRIVER, | ||
FOLLOWER, | ||
LOCAL, | ||
EMPTY | ||
} | ||
|
||
export interface FileSystemCapabilities { | ||
|
||
/** | ||
* Get a text file content | ||
* @param params the resourceUri of the file | ||
* @returns The ReadFileResult containing the content of the file | ||
*/ | ||
readFile(params: FileReadRequest): Promise<FileReadRequestResult> | ||
|
||
/** | ||
* Save a file on the filesystem | ||
* @param params the resourceUri and the content of the file | ||
* @returns The FileUpdateResult containing the result of the operation and an optional message | ||
*/ | ||
writeFile(params: FileUpdate): Promise<FileUpdateResult>; | ||
|
||
/** | ||
* The implementation has to decide if the file at given uri at need to be updated | ||
* @param params the resourceUri and the content of the file | ||
* @returns The FileUpdateResult containing the result of the operation and an optional message | ||
*/ | ||
syncFile(params: FileUpdate): Promise<FileUpdateResult>; | ||
|
||
/** | ||
* Get file stats on a given file | ||
* @param params the resourceUri and if a file or a directory is requested | ||
*/ | ||
getFileStats(params: StatsRequest): Promise<StatsRequestResult> | ||
|
||
/** | ||
* List the files of a directory | ||
* @param resourceUri the Uri of the directory | ||
*/ | ||
listFiles(params: DirectoryListingRequest): Promise<DirectoryListingRequestResult> | ||
|
||
} | ||
|
||
/** | ||
* Defines the APT for a file system endpoint | ||
*/ | ||
export interface FileSystemEndpoint extends FileSystemCapabilities { | ||
|
||
/** | ||
* Whatever can't be handled in the constructor should be done here | ||
*/ | ||
init?(): void; | ||
|
||
/** | ||
* Set an optional logger | ||
* @param logger the logger implemenation | ||
*/ | ||
setLogger?(logger: Logger): void; | ||
|
||
/** | ||
* Get the type of the client | ||
*/ | ||
getEndpointType(): EndpointType; | ||
|
||
/** | ||
* Provide info about the file system | ||
*/ | ||
getFileSystemInfo(): string; | ||
|
||
/** | ||
* Signal readiness | ||
*/ | ||
ready?(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2024 TypeFox and others. | ||
* Licensed under the MIT License. See LICENSE in the package root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
import { Logger } from 'monaco-languageclient/tools'; | ||
import { DirectoryListingRequest, DirectoryListingRequestResult, EndpointType, FileReadRequest, FileReadRequestResult, FileSystemEndpoint, FileUpdate, FileUpdateResult, StatsRequest, StatsRequestResult } from '../definitions.js'; | ||
|
||
export class EmptyFileSystemEndpoint implements FileSystemEndpoint { | ||
|
||
private endpointType: EndpointType; | ||
private logger?: Logger; | ||
|
||
constructor(endpointType: EndpointType) { | ||
this.endpointType = endpointType; | ||
} | ||
|
||
init(): void { } | ||
|
||
getFileSystemInfo(): string { | ||
return 'This file system performs no operations.'; | ||
} | ||
|
||
setLogger(logger: Logger): void { | ||
this.logger = logger; | ||
} | ||
|
||
getEndpointType(): EndpointType { | ||
return this.endpointType; | ||
} | ||
|
||
readFile(params: FileReadRequest): Promise<FileReadRequestResult> { | ||
this.logger?.info(`Reading file: ${params.resourceUri}`); | ||
return Promise.resolve({ | ||
status: 'denied', | ||
content: '' | ||
}); | ||
} | ||
|
||
writeFile(params: FileUpdate): Promise<FileUpdateResult> { | ||
this.logger?.info(`Writing file: ${params.resourceUri}`); | ||
return Promise.resolve({ status: 'denied' }); | ||
} | ||
|
||
syncFile(params: FileUpdate): Promise<FileUpdateResult> { | ||
this.logger?.info(`Syncing file: ${params.resourceUri}`); | ||
return Promise.resolve({ status: 'denied' }); | ||
} | ||
|
||
getFileStats(params: StatsRequest): Promise<StatsRequestResult> { | ||
this.logger?.info(`Getting file stats for: "${params.resourceUri}" (${params.type})`); | ||
return Promise.reject('No stats available.'); | ||
} | ||
|
||
listFiles(params: DirectoryListingRequest): Promise<DirectoryListingRequestResult> { | ||
this.logger?.info(`Listing files for directory: "${params.directoryUri}"`); | ||
return Promise.reject('No file listing possible.'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2024 TypeFox and others. | ||
* Licensed under the MIT License. See LICENSE in the package root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
export * from './definitions.js'; | ||
export * from './endpoints/defaultEndpoint.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2024 TypeFox and others. | ||
* Licensed under the MIT License. See LICENSE in the package root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
import { describe, expect, test } from 'vitest'; | ||
import { EmptyFileSystemEndpoint, EndpointType } from 'monaco-languageclient/fs'; | ||
|
||
describe('EmptyFileSystemEndpoint Tests', () => { | ||
|
||
const endpoint = new EmptyFileSystemEndpoint(EndpointType.EMPTY); | ||
|
||
test('readFile', async () => { | ||
const result = await endpoint.readFile({ resourceUri: '/tmp/test.js' }); | ||
expect(result).toEqual({ | ||
status: 'denied', | ||
content: '' | ||
}); | ||
}); | ||
|
||
test('writeFile', async () => { | ||
const result = await endpoint.writeFile({ | ||
resourceUri: '/tmp/test.js', | ||
content: 'console.log("Hello World!");' | ||
}); | ||
expect(result).toEqual({ | ||
status: 'denied' | ||
}); | ||
}); | ||
|
||
test('syncFile', async () => { | ||
const result = await endpoint.syncFile({ | ||
resourceUri: '/tmp/test.js', | ||
content: 'console.log("Hello World!");' | ||
}); | ||
expect(result).toEqual({ | ||
status: 'denied' | ||
}); | ||
}); | ||
|
||
test('getFileStats', async () => { | ||
expect(async () => { | ||
await endpoint.getFileStats({ | ||
type: 'file', | ||
resourceUri: '/tmp/test.js' | ||
}); | ||
}).rejects.toThrowError('No stats available.'); | ||
}); | ||
|
||
test('listFiles', async () => { | ||
expect(async () => { | ||
await endpoint.listFiles({ | ||
directoryUri: '/tmp' | ||
}); | ||
}).rejects.toThrowError('No file listing possible.'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
|
||
All notable changes to this npm module are documented in this file. | ||
|
||
## [2024.10.5] - 2024-10-2x | ||
|
||
- Added clangd example. | ||
|
||
## [2024.10.4] - 2024-10-23 | ||
|
||
- Updated to `[email protected]`, `[email protected]` and `@typefox/[email protected]`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.