Skip to content

Commit

Permalink
integration/rustAnalyzer: support rust-nightly
Browse files Browse the repository at this point in the history
Fixes #232
  • Loading branch information
SeaDve authored and bilelmoussaoui committed Apr 12, 2024
1 parent ab44713 commit c211a82
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/flatpak.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ export interface Source {
sha256?: string
}

export type SdkExtension = 'vala' | 'rust'
export type SdkExtension = 'vala'
| 'rust-stable'
| 'rust-nightly'
14 changes: 10 additions & 4 deletions src/integration/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ export abstract class Integration {
* Derive from this when creating an integration that requires a specific SDK extension.
*/
export abstract class SdkIntegration extends Integration {
private readonly requiredSdkExtension: SdkExtension
private readonly associatedSdkExtensions: SdkExtension[]

constructor(extensionId: string, requiredSdkExtension: SdkExtension) {
constructor(extensionId: string, associatedSdkExtensions: SdkExtension[]) {
super(extensionId)
this.requiredSdkExtension = requiredSdkExtension
this.associatedSdkExtensions = associatedSdkExtensions
}

isApplicable(manifest: Manifest): boolean {
return manifest.sdkExtensions().includes(this.requiredSdkExtension)
for (const sdkExtension of this.associatedSdkExtensions) {
if (manifest.sdkExtensions().includes(sdkExtension)) {
return true
}
}

return false
}
}
16 changes: 13 additions & 3 deletions src/integration/rustAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ import { SdkIntegration } from './base'

export class RustAnalyzer extends SdkIntegration {
constructor() {
super('rust-lang.rust-analyzer', 'rust')
super('rust-lang.rust-analyzer', ['rust-stable', 'rust-nightly'])
}

async load(manifest: Manifest): Promise<void> {
await manifest.overrideWorkspaceCommandConfig('rust-analyzer', 'server.path', 'rust-analyzer', '/usr/lib/sdk/rust-stable/bin/')
let sdkFolder
if (manifest.sdkExtensions().includes('rust-nightly')) {
sdkFolder = 'rust-nightly'
} else if (manifest.sdkExtensions().includes('rust-stable')) {
sdkFolder = 'rust-stable'
} else {
throw new Error('unreachable code')
}
const binPath = `/usr/lib/sdk/${sdkFolder}/bin/`

await manifest.overrideWorkspaceCommandConfig('rust-analyzer', 'server.path', 'rust-analyzer', binPath)

const buildSystemBuildDir = manifest.buildSystemBuildDir()
if (buildSystemBuildDir !== null) {
const envArgs = new Map([['CARGO_HOME', `${buildSystemBuildDir}/cargo-home`]])
await manifest.overrideWorkspaceCommandConfig('rust-analyzer', 'runnables.command', 'cargo', '/usr/lib/sdk/rust-stable/bin/', envArgs)
await manifest.overrideWorkspaceCommandConfig('rust-analyzer', 'runnables.command', 'cargo', binPath, envArgs)
}

await manifest.overrideWorkspaceConfig('rust-analyzer', 'files.excludeDirs', ['.flatpak', '.flatpak-builder', '_build', 'build', 'builddir'])
Expand Down
2 changes: 1 addition & 1 deletion src/integration/vala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SdkIntegration } from './base'

export class Vala extends SdkIntegration {
constructor() {
super('prince781.vala', 'vala')
super('prince781.vala', ['vala'])
}

async load(manifest: Manifest): Promise<void> {
Expand Down
4 changes: 3 additions & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ export class Manifest {

switch (suffix) {
case 'rust-stable':
sdkExtensions.push('rust-stable')
break
case 'rust-nightly':
sdkExtensions.push('rust')
sdkExtensions.push('rust-nightly')
break
case 'vala':
sdkExtensions.push('vala')
Expand Down

0 comments on commit c211a82

Please sign in to comment.