-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5715: PRJ: Project generation with cargo-generate r=ortem a=avrong Currently, it is project generation using cargo-generate merged with standard cargo templates. ## CLion <img width="912" alt="image" src="https://user-images.githubusercontent.com/6342851/88849247-4baad880-d1f2-11ea-8eb6-17f8e9b178ab.png"> ## IntelliJ IDEA <img width="929" alt="Frame 1(3)" src="https://user-images.githubusercontent.com/6342851/88853074-dc37e780-d1f7-11ea-8570-bcdef26ef108.png"> Related to #3066 Additionally: Closes #5746 Co-authored-by: Aleksei Trifonov <[email protected]>
- Loading branch information
Showing
10 changed files
with
284 additions
and
55 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
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
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/org/rust/ide/newProject/RsProjectTemplate.kt
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,26 @@ | ||
/* | ||
* Use of this source code is governed by the MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
package org.rust.ide.newProject | ||
|
||
import com.intellij.icons.AllIcons | ||
import org.rust.ide.icons.RsIcons | ||
import javax.swing.Icon | ||
|
||
sealed class RsProjectTemplate(val name: String, val isBinary: Boolean) { | ||
abstract val icon: Icon | ||
|
||
fun validateProjectName(crateName: String): String? = RsPackageNameValidator.validate(crateName, isBinary) | ||
} | ||
|
||
class RsGenericTemplate(name: String, isBinary: Boolean) : RsProjectTemplate(name, isBinary) { | ||
override val icon: Icon = RsIcons.RUST | ||
} | ||
|
||
class RsCustomTemplate(name: String, val link: String, isBinary: Boolean = true) : RsProjectTemplate(name, isBinary) { | ||
override val icon: Icon = AllIcons.Vcs.Vendors.Github | ||
val shortLink: String | ||
get() = link.substringAfter("//") | ||
} |
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,35 @@ | ||
/* | ||
* Use of this source code is governed by the MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
package org.rust.ide.newProject | ||
|
||
import com.intellij.ide.util.PsiNavigationSupport | ||
import com.intellij.openapi.application.invokeLater | ||
import com.intellij.openapi.module.Module | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.openapiext.isHeadlessEnvironment | ||
import org.rust.cargo.toolchain.Cargo | ||
import org.rust.cargo.toolchain.Cargo.Companion.GeneratedFilesHolder | ||
|
||
fun Project.openFiles(files: GeneratedFilesHolder) = invokeLater { | ||
if (!isHeadlessEnvironment) { | ||
val navigation = PsiNavigationSupport.getInstance() | ||
navigation.createNavigatable(this, files.manifest, -1).navigate(false) | ||
for (file in files.sourceFiles) { | ||
navigation.createNavigatable(this, file, -1).navigate(true) | ||
} | ||
} | ||
} | ||
|
||
fun Cargo.makeProject( | ||
project: Project, | ||
module: Module, | ||
baseDir: VirtualFile, | ||
template: RsProjectTemplate | ||
): GeneratedFilesHolder? = when (template) { | ||
is RsGenericTemplate -> init(project, module, baseDir, template.isBinary) | ||
is RsCustomTemplate -> generate(project, module, baseDir, template.link) | ||
} |
Oops, something went wrong.