Skip to content

Commit 891f8c2

Browse files
authored
Merge pull request #2403 from akshita31/absolute_package
Using absolute path and installable package classes
2 parents 671e602 + a78322a commit 891f8c2

22 files changed

+209
-131
lines changed

src/CSharpExtDownloader.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { EventStream } from './EventStream';
1010
import { DownloadAndInstallPackages } from './packageManager/PackageManager';
1111
import { Package } from './packageManager/Package';
1212
import { NetworkSettingsProvider } from './NetworkSettings';
13-
import { ResolveFilePaths } from './packageManager/PackageFilePathResolver';
1413

1514
/*
1615
* Class used to download the runtime dependencies of the C# Extension
@@ -21,7 +20,8 @@ export class CSharpExtDownloader {
2120
private networkSettingsProvider: NetworkSettingsProvider,
2221
private eventStream: EventStream,
2322
private packageJSON: any,
24-
private platformInfo: PlatformInformation) {
23+
private platformInfo: PlatformInformation,
24+
private extensionPath: string) {
2525
}
2626

2727
public async installRuntimeDependencies(): Promise<boolean> {
@@ -33,9 +33,8 @@ export class CSharpExtDownloader {
3333
// Display platform information and RID
3434
this.eventStream.post(new LogPlatformInfo(this.platformInfo));
3535
let runTimeDependencies = GetRunTimeDependenciesPackages(this.packageJSON);
36-
runTimeDependencies.forEach(pkg => ResolveFilePaths(pkg));
3736
installationStage = 'downloadAndInstallPackages';
38-
await DownloadAndInstallPackages(runTimeDependencies, this.networkSettingsProvider, this.platformInfo, this.eventStream);
37+
await DownloadAndInstallPackages(runTimeDependencies, this.networkSettingsProvider, this.platformInfo, this.eventStream, this.extensionPath);
3938
installationStage = 'touchLockFile';
4039
await util.touchInstallFile(util.InstallFileType.Lock);
4140
this.eventStream.post(new InstallationSuccess());

src/features/structureProvider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
16
import { FoldingRangeProvider, TextDocument, FoldingContext, CancellationToken, FoldingRange, FoldingRangeKind } from "vscode";
27
import AbstractSupport from './abstractProvider';
38
import { blockStructure } from "../omnisharp/utils";

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
112112
let runtimeDependenciesExist = await ensureRuntimeDependencies(extension, eventStream, platformInfo, networkSettingsProvider);
113113

114114
// activate language services
115-
let omniSharpPromise = OmniSharp.activate(context, extension.packageJSON, platformInfo, networkSettingsProvider, eventStream, optionProvider);
115+
let omniSharpPromise = OmniSharp.activate(context, extension.packageJSON, platformInfo, networkSettingsProvider, eventStream, optionProvider, extension.extensionPath);
116116

117117
// register JSON completion & hover providers for project.json
118118
context.subscriptions.push(addJSONProviders());
@@ -142,7 +142,7 @@ async function ensureRuntimeDependencies(extension: vscode.Extension<CSharpExten
142142
return util.installFileExists(util.InstallFileType.Lock)
143143
.then(exists => {
144144
if (!exists) {
145-
const downloader = new CSharpExtDownloader(networkSettingsProvider, eventStream, extension.packageJSON, platformInfo);
145+
const downloader = new CSharpExtDownloader(networkSettingsProvider, eventStream, extension.packageJSON, platformInfo, extension.extensionPath);
146146
return downloader.installRuntimeDependencies();
147147
} else {
148148
return true;

src/omnisharp/OmnisharpDownloader.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { EventStream } from '../EventStream';
1010
import { NetworkSettingsProvider } from '../NetworkSettings';
1111
import { DownloadAndInstallPackages } from '../packageManager/PackageManager';
1212
import { DownloadFile } from '../packageManager/FileDownloader';
13-
import { ResolveFilePaths } from '../packageManager/PackageFilePathResolver';
1413

1514
export class OmnisharpDownloader {
1615

1716
public constructor(
1817
private networkSettingsProvider: NetworkSettingsProvider,
1918
private eventStream: EventStream,
2019
private packageJSON: any,
21-
private platformInfo: PlatformInformation) {
20+
private platformInfo: PlatformInformation,
21+
private extensionPath: string) {
2222
}
2323

2424
public async DownloadAndInstallOmnisharp(version: string, serverUrl: string, installPath: string) {
@@ -29,9 +29,8 @@ export class OmnisharpDownloader {
2929
this.eventStream.post(new LogPlatformInfo(this.platformInfo));
3030
installationStage = 'getPackageInfo';
3131
let packages = GetPackagesFromVersion(version, this.packageJSON.runtimeDependencies, serverUrl, installPath);
32-
packages.forEach(pkg => ResolveFilePaths(pkg));
3332
installationStage = 'downloadAndInstallPackages';
34-
await DownloadAndInstallPackages(packages, this.networkSettingsProvider, this.platformInfo, this.eventStream);
33+
await DownloadAndInstallPackages(packages, this.networkSettingsProvider, this.platformInfo, this.eventStream, this.extensionPath);
3534
this.eventStream.post(new InstallationSuccess());
3635
}
3736
catch (error) {

src/omnisharp/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ import { StructureProvider } from '../features/structureProvider';
3838

3939
export let omnisharp: OmniSharpServer;
4040

41-
export async function activate(context: vscode.ExtensionContext, packageJSON: any, platformInfo: PlatformInformation, provider: NetworkSettingsProvider, eventStream: EventStream, optionProvider: OptionProvider) {
41+
export async function activate(context: vscode.ExtensionContext, packageJSON: any, platformInfo: PlatformInformation, provider: NetworkSettingsProvider, eventStream: EventStream, optionProvider: OptionProvider, extensionPath: string) {
4242
const documentSelector: vscode.DocumentSelector = {
4343
language: 'csharp',
4444
scheme: 'file' // only files from disk
4545
};
4646

4747
const options = optionProvider.GetLatestOptions();
48-
const server = new OmniSharpServer(vscode, provider, packageJSON, platformInfo, eventStream, optionProvider);
48+
const server = new OmniSharpServer(vscode, provider, packageJSON, platformInfo, eventStream, optionProvider, extensionPath);
4949
omnisharp = server;
5050
const advisor = new Advisor(server); // create before server is started
5151
const disposables = new CompositeDisposable();

src/omnisharp/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ export class OmniSharpServer {
9191
private updateProjectDebouncer = new Subject<ObservableEvents.ProjectModified>();
9292
private firstUpdateProject: boolean;
9393

94-
constructor(private vscode: vscode, networkSettingsProvider: NetworkSettingsProvider, private packageJSON: any, private platformInfo: PlatformInformation, private eventStream: EventStream, private optionProvider: OptionProvider) {
94+
constructor(private vscode: vscode, networkSettingsProvider: NetworkSettingsProvider, private packageJSON: any, private platformInfo: PlatformInformation, private eventStream: EventStream, private optionProvider: OptionProvider, extensionPath: string) {
9595
this._requestQueue = new RequestQueueCollection(this.eventStream, 8, request => this._makeRequest(request));
96-
let downloader = new OmnisharpDownloader(networkSettingsProvider, this.eventStream, this.packageJSON, platformInfo);
96+
let downloader = new OmnisharpDownloader(networkSettingsProvider, this.eventStream, this.packageJSON, platformInfo, extensionPath);
9797
this._omnisharpManager = new OmnisharpManager(downloader, platformInfo);
9898
this.updateProjectDebouncer.debounceTime(1500).subscribe((event) => { this.updateProjectInfo(); });
9999
this.firstUpdateProject = true;

src/packageManager/AbsolutePath.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { isAbsolute, resolve } from "path";
7+
8+
export class AbsolutePath{
9+
constructor(public value: string) {
10+
if (!isAbsolute(value)) {
11+
throw new Error("The path must be absolute");
12+
}
13+
}
14+
15+
public static getAbsolutePath(...pathSegments: string[]): AbsolutePath {
16+
return new AbsolutePath(resolve(...pathSegments));
17+
}
18+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { Package } from "./Package";
7+
import { IPackage } from "./IPackage";
8+
import { AbsolutePath } from "./AbsolutePath";
9+
10+
export class AbsolutePathPackage implements IPackage{
11+
constructor(public description: string,
12+
public url: string,
13+
public platforms: string[],
14+
public architectures: string[],
15+
public binaries: AbsolutePath[],
16+
public installPath?: AbsolutePath,
17+
public installTestPath?: AbsolutePath,
18+
public fallbackUrl?: string,
19+
public platformId?: string) {
20+
}
21+
22+
public static getAbsolutePathPackage(pkg: Package, extensionPath: string) {
23+
return new AbsolutePathPackage(
24+
pkg.description,
25+
pkg.url,
26+
pkg.platforms,
27+
pkg.architectures,
28+
getAbsoluteBinaries(pkg, extensionPath),
29+
getAbsoluteInstallPath(pkg, extensionPath),
30+
getAbsoluteInstallTestPath(pkg, extensionPath),
31+
pkg.fallbackUrl,
32+
pkg.platformId
33+
);
34+
}
35+
}
36+
37+
function getAbsoluteInstallTestPath(pkg: Package, extensionPath: string): AbsolutePath {
38+
if (pkg.installTestPath) {
39+
return AbsolutePath.getAbsolutePath(extensionPath, pkg.installTestPath);
40+
}
41+
42+
return null;
43+
}
44+
45+
function getAbsoluteBinaries(pkg: Package, extensionPath: string): AbsolutePath[] {
46+
let basePath = getAbsoluteInstallPath(pkg, extensionPath).value;
47+
if (pkg.binaries) {
48+
return pkg.binaries.map(value => AbsolutePath.getAbsolutePath(basePath, value));
49+
}
50+
51+
return null;
52+
}
53+
54+
function getAbsoluteInstallPath(pkg: Package, extensionPath: string): AbsolutePath {
55+
if (pkg.installPath) {
56+
return AbsolutePath.getAbsolutePath(extensionPath, pkg.installPath);
57+
}
58+
59+
return new AbsolutePath(extensionPath);
60+
}

src/packageManager/IPackage.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
export interface IPackage {
7+
description: string;
8+
url: string;
9+
fallbackUrl?: string;
10+
platforms: string[];
11+
architectures: string[];
12+
platformId?: string;
13+
}

src/packageManager/Package.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
export interface Package {
7-
description: string;
8-
url: string;
9-
fallbackUrl?: string;
6+
import { IPackage } from "./IPackage";
7+
8+
export interface Package extends IPackage{
109
installPath?: string;
11-
platforms: string[];
12-
architectures: string[];
1310
binaries: string[];
14-
platformId?: string;
15-
// Path to use to test if the package has already been installed
1611
installTestPath?: string;
1712
}

0 commit comments

Comments
 (0)