Skip to content

Commit

Permalink
feat: allow overriding determineProjectPath
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 10, 2021
1 parent 813fbde commit d3f213f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 11 additions & 1 deletion lib/auto-languageclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ export default class AutoLanguageClient {
(e) => this.shouldStartForEditor(e),
(filepath) => this.filterChangeWatchedFiles(filepath),
this.reportBusyWhile,
this.getServerName()
this.getServerName(),
this.determineProjectPath
)
this._serverManager.startListening()
process.on("exit", () => this.exitCleanup.bind(this))
Expand Down Expand Up @@ -477,6 +478,15 @@ export default class AutoLanguageClient {
this.logger.debug(`exit: code ${code} signal ${signal}`)
}

/** (Optional) Finds the project path. If there is a custom logic for finding projects override this method. */
protected determineProjectPath(textEditor: TextEditor): string | null {
const filePath = textEditor.getPath()
if (filePath == null) {
return null
}
return this._serverManager.getNormalizedProjectPaths().find((d) => filePath.startsWith(d)) || null
}

/**
* The function called whenever the spawned server returns `data` in `stderr` Extend (call super.onSpawnStdErrData) or
* override this if you need custom stderr data handling
Expand Down
13 changes: 3 additions & 10 deletions lib/server-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export class ServerManager {
private _startForEditor: (editor: TextEditor) => boolean,
private _changeWatchedFileFilter: (filePath: string) => boolean,
private _reportBusyWhile: ReportBusyWhile,
private _languageServerName: string
private _languageServerName: string,
private _determineProjectPath: (textEditor: TextEditor) => string | null
) {
this.updateNormalizedProjectPaths()
}
Expand Down Expand Up @@ -121,7 +122,7 @@ export class ServerManager {
textEditor: TextEditor,
{ shouldStart }: { shouldStart?: boolean } = { shouldStart: false }
): Promise<ActiveServer | null> {
const finalProjectPath = this.determineProjectPath(textEditor)
const finalProjectPath = this._determineProjectPath(textEditor)
if (finalProjectPath == null) {
// Files not yet saved have no path
return null
Expand Down Expand Up @@ -245,14 +246,6 @@ export class ServerManager {
})
}

public determineProjectPath(textEditor: TextEditor): string | null {
const filePath = textEditor.getPath()
if (filePath == null) {
return null
}
return this._normalizedProjectPaths.find((d) => filePath.startsWith(d)) || null
}

public updateNormalizedProjectPaths(): void {
this._normalizedProjectPaths = atom.project.getPaths().map(normalizePath)
}
Expand Down

0 comments on commit d3f213f

Please sign in to comment.