Skip to content

Commit 595475e

Browse files
feat: inject home directory into runtimes. (#424)
* feat: add workspace.fs.getUserHomeDir for expanding ~ * fix: avoid undefined assertion Co-authored-by: Justin M. Keyes <[email protected]> * refactor: use default home dir * refactor: join server name to serverPath on web --------- Co-authored-by: Justin M. Keyes <[email protected]>
1 parent 27977de commit 595475e

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

runtimes/runtimes/base-runtime.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import { Service } from 'aws-sdk'
7979
import { ServiceConfigurationOptions } from 'aws-sdk/lib/service'
8080
import { getClientInitializeParamsHandlerFactory } from './util/lspCacheUtil'
8181
import { newAgent } from './agent'
82+
import { join } from 'path'
8283

8384
declare const self: WindowOrWorkerGlobalScope
8485

@@ -107,6 +108,7 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
107108
}
108109

109110
// Set up the workspace to use the LSP Text Documents component
111+
const defaultHomeDir = '/home/user'
110112
const workspace: Workspace = {
111113
getTextDocument: async uri => documents.get(uri),
112114
getAllTextDocuments: async () => documents.all(),
@@ -116,8 +118,13 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
116118
copyFile: (_src, _dest, _options?) => Promise.resolve(),
117119
exists: _path => Promise.resolve(false),
118120
getFileSize: _path => Promise.resolve({ size: 0 }),
119-
getServerDataDirPath: _serverName => '',
121+
getServerDataDirPath: serverName =>
122+
join(
123+
lspRouter.clientInitializeParams?.initializationOptions?.aws?.clientDataFolder ?? defaultHomeDir,
124+
serverName
125+
),
120126
getTempDirPath: () => '/tmp',
127+
getUserHomeDir: () => defaultHomeDir,
121128
readFile: (_path, _options?) => Promise.resolve(''),
122129
readdir: _path => Promise.resolve([]),
123130
isFile: _path => Promise.resolve(false),

runtimes/runtimes/standalone.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export const standalone = (props: RuntimeProps) => {
213213
os.type() === 'Darwin' ? '/tmp' : os.tmpdir(),
214214
'aws-language-servers'
215215
),
216+
getUserHomeDir: () => os.homedir(),
216217
readdir: path => readdir(path, { withFileTypes: true }),
217218
readFile: (path, options?) =>
218219
readFile(path, { encoding: (options?.encoding || 'utf-8') as BufferEncoding }),

runtimes/server-interface/workspace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type Workspace = {
3232
getFileSize: (path: string) => Promise<{ size: number }>
3333
getServerDataDirPath: (serverName: string) => string
3434
getTempDirPath: () => string
35+
getUserHomeDir: () => string
3536
/**
3637
* Reads the contents of a directory.
3738
* @param {string} path - The path to the directory.

0 commit comments

Comments
 (0)