|
|
@@ -9,11 +9,17 @@ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service
|
|
|
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
|
|
|
import { ProblemManager } from '@theia/markers/lib/browser/problem/problem-manager';
|
|
|
import { Diagnostic, DiagnosticSeverity } from '@theia/core/shared/vscode-languageserver-protocol';
|
|
|
+import { PreferenceContribution } from '@theia/core/lib/common/preferences/preference-schema';
|
|
|
+import { PreferenceService } from '@theia/core/lib/common/preferences/preference-service';
|
|
|
+import { TaskContribution } from '@theia/task/lib/browser/task-contribution';
|
|
|
import URI from '@theia/core/lib/common/uri';
|
|
|
import {
|
|
|
BuildDiagnostic, BuildResult, Modula2Compiler, Modula2CompilerServicePath,
|
|
|
- Modula2Project, parseProjectFile,
|
|
|
+ Modula2Project,
|
|
|
} from '../common/compiler';
|
|
|
+import { COMPILER_OPTIONS, COMPILER_PATH, modula2PreferenceSchema } from './modula2-preferences';
|
|
|
+import { loadWorkspaceProject } from './modula2-project';
|
|
|
+import { Modula2TaskContribution, Modula2TaskProvider, Modula2TaskResolver } from './modula2-tasks';
|
|
|
|
|
|
const CATEGORY = 'Modula-2';
|
|
|
|
|
|
@@ -45,6 +51,7 @@ class CompilerCommands implements CommandContribution {
|
|
|
@inject(EditorManager) protected readonly editors: EditorManager;
|
|
|
@inject(MessageService) protected readonly messages: MessageService;
|
|
|
@inject(ProblemManager) protected readonly problems: ProblemManager;
|
|
|
+ @inject(PreferenceService) protected readonly prefs: PreferenceService;
|
|
|
/** URIs currently carrying our markers, so stale ones can be cleared. */
|
|
|
protected readonly markedUris = new Set<string>();
|
|
|
|
|
|
@@ -59,21 +66,21 @@ class CompilerCommands implements CommandContribution {
|
|
|
commands.registerCommand(Commands.run, { execute: () => this.withProject(p => this.run(p)) });
|
|
|
}
|
|
|
|
|
|
- /** Load modula2.json from the first workspace root. */
|
|
|
+ /** Load modula2.json from the first workspace root, applying preferences. */
|
|
|
protected async loadProject(): Promise<Modula2Project | undefined> {
|
|
|
- const roots = await this.workspace.roots;
|
|
|
- if (roots.length === 0) {
|
|
|
+ const loaded = await loadWorkspaceProject(this.files, this.workspace);
|
|
|
+ if (!loaded) {
|
|
|
this.messages.warn('Modula-2: open a folder with a modula2.json project first.');
|
|
|
return undefined;
|
|
|
}
|
|
|
- const rootUri = roots[0].resource;
|
|
|
- try {
|
|
|
- const content = await this.files.read(rootUri.resolve('modula2.json'));
|
|
|
- return parseProjectFile(rootUri.path.fsPath(), content.value);
|
|
|
- } catch {
|
|
|
- this.messages.warn('Modula-2: no readable modula2.json in the workspace root.');
|
|
|
- return undefined;
|
|
|
+ const project = loaded.project;
|
|
|
+ // Preferences fill the gaps: an explicit modula2.json path always wins.
|
|
|
+ if (!project.compilerPathExplicit) {
|
|
|
+ project.compiler.path = this.prefs.get<string>(COMPILER_PATH, 'gm2');
|
|
|
}
|
|
|
+ const extra = this.prefs.get<string[]>(COMPILER_OPTIONS, []);
|
|
|
+ project.compiler.options = [...project.compiler.options, ...extra];
|
|
|
+ return project;
|
|
|
}
|
|
|
|
|
|
protected async withProject(op: (project: Modula2Project) => Promise<void>): Promise<void> {
|
|
|
@@ -171,19 +178,24 @@ class CompilerCommands implements CommandContribution {
|
|
|
}
|
|
|
|
|
|
protected async detect(): Promise<void> {
|
|
|
- const info = await this.compiler.detect('gm2');
|
|
|
+ const configured = this.prefs.get<string>(COMPILER_PATH, 'gm2');
|
|
|
+ const info = await this.compiler.detect(configured);
|
|
|
if (info) {
|
|
|
this.messages.info(`GNU Modula-2 detected: ${info.version} (${info.path})`);
|
|
|
} else {
|
|
|
- this.messages.warn('Modula-2: no working gm2 executable found on PATH.');
|
|
|
+ this.messages.warn(`Modula-2: no working compiler at "${configured}".`);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export default new ContainerModule(bind => {
|
|
|
+ bind(PreferenceContribution).toConstantValue({ schema: modula2PreferenceSchema });
|
|
|
bind(Modula2Compiler).toDynamicValue(ctx => {
|
|
|
const provider = ctx.container.get<ServiceConnectionProvider>(RemoteConnectionProvider);
|
|
|
return provider.createProxy<Modula2Compiler>(Modula2CompilerServicePath);
|
|
|
}).inSingletonScope();
|
|
|
bind(CommandContribution).to(CompilerCommands).inSingletonScope();
|
|
|
+ bind(Modula2TaskProvider).toSelf().inSingletonScope();
|
|
|
+ bind(Modula2TaskResolver).toSelf().inSingletonScope();
|
|
|
+ bind(TaskContribution).to(Modula2TaskContribution).inSingletonScope();
|
|
|
});
|