Skip to content

Commit

Permalink
chore: move getWorkspaceFolders to ServerManager
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed May 6, 2021
1 parent de845ff commit 54003e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
24 changes: 1 addition & 23 deletions lib/auto-languageclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,35 +573,13 @@ export default class AutoLanguageClient {

ShowDocumentAdapter.attach(server.connection)

server.connection.onWorkspaceFolders(() => this.getWorkspaceFolders())
server.connection.onWorkspaceFolders(() => this._serverManager.getWorkspaceFolders())
}

public shouldSyncForEditor(editor: TextEditor, projectPath: string): boolean {
return this.isFileInProject(editor, projectPath) && this.shouldStartForEditor(editor)
}

/**
* Public: fetch the current open list of workspace folders
*
* @param getProjectPaths A method that returns the open atom projects. This is passed from {ServerManager.getProjectPaths}
* @returns A {Promise} containing an {Array} of {lsp.WorkspaceFolder[]} or {null} if only a single file is open in the tool.
*/
public getWorkspaceFolders(): Promise<ls.WorkspaceFolder[] | null> {
// NOTE the method must return a Promise based on the specification
const projectPaths = this._serverManager.getProjectPaths()
if (projectPaths.length === 0) {
// only a single file is open
return Promise.resolve(null)
} else {
return Promise.resolve(
projectPaths.map((projectPath) => ({
uri: Convert.pathToUri(projectPath),
name: basename(projectPath),
}))
)
}
}

protected isFileInProject(editor: TextEditor, projectPath: string): boolean {
return (editor.getPath() || "").startsWith(projectPath)
}
Expand Down
22 changes: 22 additions & 0 deletions lib/server-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,28 @@ export class ServerManager {
return this._normalizedProjectPaths
}

/**
* Public: fetch the current open list of workspace folders
*
* @param getProjectPaths A method that returns the open atom projects. This is passed from {ServerManager.getProjectPaths}
* @returns A {Promise} containing an {Array} of {lsp.WorkspaceFolder[]} or {null} if only a single file is open in the tool.
*/
public getWorkspaceFolders(): Promise<ls.WorkspaceFolder[] | null> {
// NOTE the method must return a Promise based on the specification
const projectPaths = this.getProjectPaths()
if (projectPaths.length === 0) {
// only a single file is open
return Promise.resolve(null)
} else {
return Promise.resolve(
projectPaths.map((projectPath) => ({
uri: Convert.pathToUri(projectPath),
name: path.basename(projectPath),
}))
)
}
}

public normalizePath(projectPath: string): string {
return !projectPath.endsWith(path.sep) ? path.join(projectPath, path.sep) : projectPath
}
Expand Down

0 comments on commit 54003e4

Please sign in to comment.