-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for workspace folders
More information https://bit.ly/3uou37n
- Loading branch information
Showing
4 changed files
with
64 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { LanguageClientConnection, WorkspaceFolder } from "../languageclient" | ||
import Convert from "../convert" | ||
import { basename } from "path" | ||
|
||
/** Public: Adapts the window/workspaceFolders command to Atom. */ | ||
const WorkspaceFoldersAdapter = { | ||
/** {@inheritDoc attach} */ | ||
attach, | ||
/** {@inheritDoc getWorkspaceFolders} */ | ||
getWorkspaceFolders, | ||
} | ||
export default WorkspaceFoldersAdapter | ||
|
||
/** | ||
* Public: Attach to a {LanguageClientConnection} to fetch the current open list of workspace folders. | ||
* | ||
* @param connection The {LanguageClientConnection} | ||
* @param getProjectPaths A method that returns the open atom projects. This is passed from {ServerManager.getProjectPaths} | ||
*/ | ||
export function attach(connection: LanguageClientConnection, getProjectPaths: () => string[]): void { | ||
connection.onWorkspaceFolders(() => getWorkspaceFolders(getProjectPaths)) | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
export async function getWorkspaceFolders(getProjectPaths: () => string[]): Promise<WorkspaceFolder[] | null> { | ||
const projectPaths = getProjectPaths() | ||
if (projectPaths.length === 0) { | ||
// only a single file is open | ||
return null | ||
} else { | ||
return projectPaths.map((projectPath) => ({ | ||
uri: Convert.pathToUri(projectPath), | ||
name: basename(projectPath), | ||
})) | ||
} | ||
} |
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