forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Out of band updates to the language server (#2615)
Fixes #2580
- Loading branch information
1 parent
6870c7c
commit e77e14c
Showing
33 changed files
with
1,026 additions
and
245 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
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 @@ | ||
Add support for out of band updates to the language server. |
Large diffs are not rendered by default.
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,68 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import * as path from 'path'; | ||
import * as semver from 'semver'; | ||
import { EXTENSION_ROOT_DIR } from '../common/constants'; | ||
import { NugetPackage } from '../common/nuget/types'; | ||
import { IFileSystem } from '../common/platform/types'; | ||
import { IConfigurationService, ILogger } from '../common/types'; | ||
import { IServiceContainer } from '../ioc/types'; | ||
import { FolderVersionPair, ILanguageServerFolderService, ILanguageServerPackageService } from './types'; | ||
|
||
const languageServerFolder = 'languageServer'; | ||
|
||
@injectable() | ||
export class LanguageServerFolderService implements ILanguageServerFolderService { | ||
constructor(@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer) { } | ||
|
||
public async getLanguageServerFolderName(): Promise<string> { | ||
const currentFolder = await this.getcurrentLanguageServerDirectory(); | ||
let serverVersion: NugetPackage | undefined; | ||
|
||
const configService = this.serviceContainer.get<IConfigurationService>(IConfigurationService); | ||
if (currentFolder && !configService.getSettings().autoUpdateLanguageServer) { | ||
return path.basename(currentFolder.path); | ||
} | ||
|
||
serverVersion = await this.getLatestLanguageServerVersion() | ||
.catch(ex => { | ||
const logger = this.serviceContainer.get<ILogger>(ILogger); | ||
logger.logError('Failed to get latest version of Language Server.', ex); | ||
return undefined; | ||
}); | ||
|
||
if (currentFolder && (!serverVersion || serverVersion.version.compare(currentFolder.version) <= 0)) { | ||
return path.basename(currentFolder.path); | ||
} | ||
|
||
return `${languageServerFolder}.${serverVersion!.version.raw}`; | ||
} | ||
public getLatestLanguageServerVersion(): Promise<NugetPackage | undefined> { | ||
const lsPackageService = this.serviceContainer.get<ILanguageServerPackageService>(ILanguageServerPackageService); | ||
return lsPackageService.getLatestNugetPackageVersion(); | ||
} | ||
public async getcurrentLanguageServerDirectory(): Promise<FolderVersionPair | undefined> { | ||
const dirs = await this.getExistingLanguageServerDirectories(); | ||
if (dirs.length === 0) { | ||
return; | ||
} | ||
const sortedDirs = dirs.sort((a, b) => a.version.compare(b.version)); | ||
return sortedDirs[sortedDirs.length - 1]; | ||
} | ||
public async getExistingLanguageServerDirectories(): Promise<FolderVersionPair[]> { | ||
const fs = this.serviceContainer.get<IFileSystem>(IFileSystem); | ||
const subDirs = await fs.getSubDirectories(EXTENSION_ROOT_DIR); | ||
return subDirs | ||
.filter(dir => path.basename(dir).startsWith(languageServerFolder)) | ||
.map(dir => { return { path: dir, version: this.getFolderVersion(path.basename(dir)) }; }); | ||
} | ||
|
||
public getFolderVersion(dirName: string): semver.SemVer { | ||
const suffix = dirName.substring(languageServerFolder.length + 1); | ||
return suffix.length === 0 ? new semver.SemVer('0.0.0') : (semver.parse(suffix, true) || new semver.SemVer('0.0.0')); | ||
} | ||
} |
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,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import { Architecture, OSType } from '../../utils/platform'; | ||
import { INugetRepository, INugetService, NugetPackage } from '../common/nuget/types'; | ||
import { IPlatformService } from '../common/platform/types'; | ||
import { IServiceContainer } from '../ioc/types'; | ||
import { PlatformName } from './platformData'; | ||
import { ILanguageServerPackageService } from './types'; | ||
|
||
const downloadBaseFileName = 'Python-Language-Server'; | ||
export const maxMajorVersion = 0; | ||
export const PackageNames = { | ||
[PlatformName.Windows32Bit]: `${downloadBaseFileName}-${PlatformName.Windows32Bit}`, | ||
[PlatformName.Windows64Bit]: `${downloadBaseFileName}-${PlatformName.Windows64Bit}`, | ||
[PlatformName.Linux64Bit]: `${downloadBaseFileName}-${PlatformName.Linux64Bit}`, | ||
[PlatformName.Mac64Bit]: `${downloadBaseFileName}-${PlatformName.Mac64Bit}` | ||
}; | ||
|
||
@injectable() | ||
export class LanguageServerPackageService implements ILanguageServerPackageService { | ||
public maxMajorVersion: number = maxMajorVersion; | ||
constructor(@inject(IServiceContainer) protected readonly serviceContainer: IServiceContainer) { } | ||
public getNugetPackageName(): string { | ||
const plaform = this.serviceContainer.get<IPlatformService>(IPlatformService); | ||
switch (plaform.info.type) { | ||
case OSType.Windows: { | ||
const is64Bit = plaform.info.architecture === Architecture.x64; | ||
return PackageNames[is64Bit ? PlatformName.Windows64Bit : PlatformName.Windows32Bit]; | ||
} | ||
case OSType.OSX: { | ||
return PackageNames[PlatformName.Mac64Bit]; | ||
} | ||
default: { | ||
return PackageNames[PlatformName.Linux64Bit]; | ||
} | ||
} | ||
} | ||
|
||
public async getLatestNugetPackageVersion(): Promise<NugetPackage> { | ||
const nugetRepo = this.serviceContainer.get<INugetRepository>(INugetRepository); | ||
const nugetService = this.serviceContainer.get<INugetService>(INugetService); | ||
const packageName = this.getNugetPackageName(); | ||
const packages = await nugetRepo.getPackages(packageName); | ||
|
||
const validPackages = packages | ||
.filter(item => item.version.major === this.maxMajorVersion) | ||
.filter(item => nugetService.isReleaseVersion(item.version)) | ||
.sort((a, b) => a.version.compare(b.version)); | ||
return validPackages[validPackages.length - 1]; | ||
} | ||
} |
Oops, something went wrong.