-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Merge getBuild and getProject requests (#1152)
- Loading branch information
Showing
25 changed files
with
298 additions
and
383 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
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,43 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import AwaitLock from "await-lock"; | ||
import { GradleClient } from "."; | ||
import { syncGradleBuild } from "../languageServer/languageServer"; | ||
import { GradleBuild } from "../proto/gradle_pb"; | ||
import { RootProject } from "../rootProject"; | ||
import { getGradleConfig } from "../util/config"; | ||
|
||
const lock = new AwaitLock(); | ||
|
||
export class GradleBuildContentProvider { | ||
private cachedBuild: Map<string, GradleBuild> = new Map(); | ||
|
||
constructor(private readonly client: GradleClient) {} | ||
|
||
public async getGradleBuild(rootProject: RootProject): Promise<GradleBuild | undefined> { | ||
await lock.acquireAsync(); | ||
try { | ||
const projectPath = rootProject.getProjectUri().fsPath; | ||
if (this.cachedBuild.has(projectPath)) { | ||
return this.cachedBuild.get(projectPath); | ||
} | ||
const gradleBuild = await this.client.getBuild(rootProject, getGradleConfig()); | ||
if (gradleBuild) { | ||
await syncGradleBuild(gradleBuild); | ||
this.cachedBuild.set(projectPath, gradleBuild); | ||
} | ||
return gradleBuild; | ||
} finally { | ||
lock.release(); | ||
} | ||
} | ||
|
||
public refresh(): void { | ||
this.cachedBuild.clear(); | ||
} | ||
|
||
public getCachedBuild(): Map<string, GradleBuild> { | ||
return this.cachedBuild; | ||
} | ||
} |
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,40 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { GradleBuild, GradleProject } from "../proto/gradle_pb"; | ||
import { RootProject } from "../rootProject"; | ||
import { RootProjectsStore } from "../stores"; | ||
|
||
export function findGradleProjectFromBuild(projectPath: string, gradleBuild: GradleBuild): GradleProject | undefined { | ||
const rootProject = gradleBuild.getProject(); | ||
if (!rootProject || !rootProject.getIsRoot()) { | ||
return undefined; | ||
} | ||
return findGradleProject(projectPath, rootProject); | ||
} | ||
|
||
function findGradleProject(projectPath: string, project: GradleProject): GradleProject | undefined { | ||
if (vscode.Uri.file(project.getProjectpath()).fsPath === projectPath) { | ||
return project; | ||
} | ||
for (const subProject of project.getProjectsList()) { | ||
const result = findGradleProject(projectPath, subProject); | ||
if (result) { | ||
return result; | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
export async function findRootProject( | ||
rootProjectStore: RootProjectsStore, | ||
projectPath: string | ||
): Promise<RootProject | undefined> { | ||
for (const rootProject of await rootProjectStore.getProjectRoots()) { | ||
if (projectPath.startsWith(rootProject.getProjectUri().fsPath)) { | ||
return rootProject; | ||
} | ||
} | ||
return undefined; | ||
} |
Oops, something went wrong.