-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for Rascal Project creation PR-redo #248
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,18 @@ import * as os from 'os'; | |
import * as path from 'path'; | ||
import * as vscode from 'vscode'; | ||
|
||
import { writeFileSync } from 'fs'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two concerns:
|
||
|
||
import { integer } from 'vscode-languageclient/node'; | ||
import { getJavaExecutable } from './auto-jvm/JavaLookup'; | ||
import { RascalLanguageServer } from './lsp/RascalLanguageServer'; | ||
import { LanguageParameter, ParameterizedLanguageServer } from './lsp/ParameterizedLanguageServer'; | ||
import { RascalTerminalLinkProvider } from './RascalTerminalLinkProvider'; | ||
import { VSCodeUriResolverServer } from './fs/VSCodeURIResolver'; | ||
|
||
const vsfs = vscode.workspace.fs; | ||
const URI = vscode.Uri; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't this be done at import time? |
||
|
||
export class RascalExtension implements vscode.Disposable { | ||
private readonly vfsServer: VSCodeUriResolverServer; | ||
private readonly dsls:ParameterizedLanguageServer; | ||
|
@@ -50,6 +55,7 @@ export class RascalExtension implements vscode.Disposable { | |
this.registerTerminalCommand(); | ||
this.registerMainRun(); | ||
this.registerImportModule(); | ||
this.createProject(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick, let's rename it to |
||
|
||
vscode.window.registerTerminalLinkProvider(new RascalTerminalLinkProvider(this.rascal.rascalClient)); | ||
} | ||
|
@@ -87,6 +93,34 @@ export class RascalExtension implements vscode.Disposable { | |
); | ||
} | ||
|
||
private createProject() { | ||
this.context.subscriptions.push( | ||
vscode.commands.registerCommand("rascalmpl.createProject", | ||
async () => { | ||
try { | ||
const filePath = await vscode.window.showOpenDialog({ | ||
canSelectFiles: false, | ||
canSelectFolders: true, | ||
canSelectMany: false, | ||
title: "New Rascal project", | ||
}); | ||
|
||
if (filePath) { | ||
const dest = filePath[0].path; | ||
const destUri = URI.file(dest); | ||
const projectName = dest.split("/").at(-1) as string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on windows the path won't be seperated by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do like the idea of forcing the projectName as a directory name in this explicit manner. We could also use the inverse, and popup some input boxes, and then ask for the root directory. |
||
|
||
newRascalProject(dest, projectName); | ||
|
||
// Open a workspace window | ||
await vscode.commands.executeCommand("vscode.openFolder", destUri, true); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if we fail the command, we should show a message, as otherwise the command has no output, it just didn't do anything observable. Using the |
||
} | ||
}) | ||
); | ||
} | ||
|
||
private registerImportModule() { | ||
this.context.subscriptions.push( | ||
|
@@ -183,3 +217,105 @@ function calculateRascalREPLMemory() { | |
} | ||
return "-Xmx800M"; | ||
} | ||
|
||
async function newRascalProject(dest: string, name: string) { | ||
|
||
const baseDest = URI.file(dest); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before calling the function, we already calculated the Uri, we could move this up, so that this can also work for non-file uri's (like virtual file systems). |
||
vsfs.createDirectory(baseDest); | ||
|
||
const metaPath = URI.joinPath(baseDest, "META-INF"); | ||
await vsfs.createDirectory(metaPath); | ||
|
||
const srcPath = URI.joinPath(baseDest, "src/main/rascal/"); | ||
await vsfs.createDirectory(srcPath); | ||
|
||
const rascalMFPath = URI.joinPath(metaPath, "RASCAL.MF"); | ||
writeFileSync(rascalMFPath.fsPath, rascalMF(name)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed earlier, we should do |
||
|
||
const pomPath = URI.joinPath(baseDest, "pom.xml"); | ||
writeFileSync(pomPath.fsPath, pomXML(name)); | ||
|
||
const mainPath = URI.joinPath(srcPath, "Main.rsc"); | ||
writeFileSync(mainPath.fsPath, emptyModule); | ||
|
||
} | ||
|
||
function rascalMF(name: string): string { | ||
return "Manifest-Version: 0.0.1\n" + | ||
`Project-Name: ${name}\n` + | ||
"Source: src/main/rascal\n" + | ||
"Require-Libraries: \n" | ||
; | ||
} | ||
|
||
function pomXML(name: string, group="org.rascalmpl", version="0.1.0-SNAPSHOT"): string { | ||
return `<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>${group}</groupId> | ||
<artifactId>${name}</artifactId> | ||
<version>${version}</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>usethesource</id> | ||
<url>https://releases.usethesource.io/maven/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>usethesource</id> | ||
<url>https://releases.usethesource.io/maven/</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.rascalmpl</groupId> | ||
<artifactId>rascal</artifactId> | ||
<version><getRascalVersion()></version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<compilerArgument>-parameters</compilerArgument> | ||
<release>11</release> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.rascalmpl</groupId> | ||
<artifactId>rascal-maven-plugin</artifactId> | ||
<version>0.8.2</version> | ||
<configuration> | ||
<errorsAsWarnings>true</errorsAsWarnings> | ||
<bin>\${project.build.outputDirectory}</bin> | ||
<srcs> | ||
<src>$\{project.basedir}/src/main/rascal</src> | ||
</srcs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> | ||
`; | ||
} | ||
|
||
const emptyModule = "module Main\n" + | ||
"import IO;\n\n"+ | ||
"int main(int testArgument=0) {\n" + | ||
` println("argument: <testArgument>");\n` + | ||
" return testArgument;\n"+ | ||
"}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a specific reason to pin point this?