Compare commits
6 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
7883e43e05 |
|||
| e74bd87c23 | |||
| ff8f68ec03 | |||
| 262d26869c | |||
| 91b7a63db5 | |||
| e480135055 |
12 changed files with 209 additions and 24 deletions
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
|
|
@ -2,6 +2,5 @@
|
|||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/src/main/resources/textmate/bundles/better-cpp-syntax" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
26
README.md
Normal file
26
README.md
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# C/C++ very basic support for IntelliJ IDEA CE
|
||||
|
||||
... or how to make an IJ IDEA a little VSCode...
|
||||
|
||||
## Includes
|
||||
- making new C or C++ file (e.g., in empty project)
|
||||
- syntax highlighting is actually provided by IJ itself;
|
||||
- refactoring, code analysis, advanced types of highlighting is provided with Language Server Protocol via lsp4ij plugin from Redhat.
|
||||
|
||||
## Not (yet) implemented
|
||||
- CMake, make, ninja any project build support (just use Terminal...);
|
||||
- STM32 (or any other embedded C) projects
|
||||
- choosing various language standards for Clangd
|
||||
- any additional checks except the clangd provides by default;
|
||||
|
||||
## Additional requirements
|
||||
- clangd visible through PATH
|
||||
- clang/clang++ for compiling projects manually
|
||||
|
||||
## How to start
|
||||
|
||||
Install plugin >> Restart IDE
|
||||
|
||||
Empty project >> New file >> New C (or C++) file
|
||||
|
||||
Enjoy!
|
||||
|
|
@ -5,7 +5,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "com.gregorybednov"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
|||
25
src/main/kotlin/org/gregorybednov/NewCFileAction.kt
Normal file
25
src/main/kotlin/org/gregorybednov/NewCFileAction.kt
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package org.gregorybednov
|
||||
|
||||
import com.intellij.ide.actions.CreateFileFromTemplateAction
|
||||
import com.intellij.ide.actions.CreateFileFromTemplateDialog
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiDirectory
|
||||
import org.gregorybednov.clsp.CIcon
|
||||
|
||||
|
||||
class NewCFileAction :
|
||||
CreateFileFromTemplateAction("C File", "Creates new C file", CIcon.FILE ) {
|
||||
override fun buildDialog(project: Project, directory: PsiDirectory, builder: CreateFileFromTemplateDialog.Builder) {
|
||||
builder
|
||||
.setTitle("New C File")
|
||||
.addKind("My file", CIcon.FILE, "DefaultTemplate.c")
|
||||
}
|
||||
|
||||
override fun getActionName(directory: PsiDirectory?, newName: String, templateName: String?): String {
|
||||
return "C File"
|
||||
}
|
||||
|
||||
override fun getDefaultTemplateProperty(): String {
|
||||
return "DefaultTemplate.c";
|
||||
}
|
||||
}
|
||||
26
src/main/kotlin/org/gregorybednov/NewCppFileAction.kt
Normal file
26
src/main/kotlin/org/gregorybednov/NewCppFileAction.kt
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package org.gregorybednov
|
||||
|
||||
import com.intellij.ide.actions.CreateFileFromTemplateAction
|
||||
import com.intellij.ide.actions.CreateFileFromTemplateDialog
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiDirectory
|
||||
import org.gregorybednov.clsp.CIcon
|
||||
import org.gregorybednov.clsp.CppIcon
|
||||
|
||||
|
||||
class NewCppFileAction :
|
||||
CreateFileFromTemplateAction("C++ File", "Creates new C++ file", CppIcon.FILE ) {
|
||||
override fun buildDialog(project: Project, directory: PsiDirectory, builder: CreateFileFromTemplateDialog.Builder) {
|
||||
builder
|
||||
.setTitle("New C++ File")
|
||||
.addKind("My file", CIcon.FILE, "DefaultTemplate.cpp")
|
||||
}
|
||||
|
||||
override fun getActionName(directory: PsiDirectory?, newName: String, templateName: String?): String {
|
||||
return "C++ File"
|
||||
}
|
||||
|
||||
override fun getDefaultTemplateProperty(): String {
|
||||
return "DefaultTemplate.cpp";
|
||||
}
|
||||
}
|
||||
65
src/main/kotlin/org/gregorybednov/clsp/CLanguage.kt
Normal file
65
src/main/kotlin/org/gregorybednov/clsp/CLanguage.kt
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
package org.gregorybednov.clsp
|
||||
|
||||
import com.intellij.execution.configurations.GeneralCommandLine
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.notification.NotificationGroupManager
|
||||
import com.intellij.notification.NotificationType
|
||||
import com.intellij.openapi.fileTypes.LanguageFileType
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.IconLoader.getIcon
|
||||
import com.intellij.util.EnvironmentUtil
|
||||
import com.redhat.devtools.lsp4ij.LanguageServerFactory
|
||||
import com.redhat.devtools.lsp4ij.LanguageServerManager
|
||||
import com.redhat.devtools.lsp4ij.server.OSProcessStreamConnectionProvider
|
||||
import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider
|
||||
import javax.swing.Icon
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import java.io.File
|
||||
import java.nio.file.Paths
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
object CLanguage : Language("C") {
|
||||
private fun readResolve(): Any = CLanguage
|
||||
val INSTANCE: CLanguage = CLanguage
|
||||
}
|
||||
|
||||
object CIcon {
|
||||
val FILE: Icon = getIcon("/icons/clogo.svg", CIcon::class.java)
|
||||
}
|
||||
|
||||
class CFileType private constructor() : LanguageFileType(CLanguage.INSTANCE) {
|
||||
override fun getName(): String { return "C File" }
|
||||
override fun getDescription(): String { return "C language file" }
|
||||
override fun getDefaultExtension(): String { return "c" }
|
||||
override fun getIcon(): Icon { return CIcon.FILE }
|
||||
companion object { val INSTANCE: CFileType = CFileType() }
|
||||
}
|
||||
|
||||
class CLanguageServer(project: Project) : OSProcessStreamConnectionProvider() {
|
||||
private fun findExecutableInPATH(executable: String) =
|
||||
EnvironmentUtil.getEnvironmentMap().values.flatMap { it.split(File.pathSeparator) }
|
||||
.map { File(Paths.get(it, executable).pathString) }.find { it.exists() && it.canExecute() }?.path
|
||||
|
||||
init {
|
||||
val clangdPath = findExecutableInPATH("clangd")
|
||||
if (clangdPath.isNullOrEmpty()) {
|
||||
NotificationGroupManager.getInstance().getNotificationGroup("C/C++ notifications").createNotification(
|
||||
"C LSP",
|
||||
"LSP server clangd not found. Make sure it is installed properly (and is available in PATH)," +
|
||||
"and restart the IDE.",
|
||||
NotificationType.ERROR).notify(project)
|
||||
LanguageServerManager.getInstance(project).stop("CLanguageServer")
|
||||
} else {
|
||||
val commandLine = GeneralCommandLine("clangd")
|
||||
commandLine.setWorkDirectory(project.basePath)
|
||||
super.setCommandLine(commandLine)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CLanguageServerFactory : LanguageServerFactory {
|
||||
@NotNull
|
||||
override fun createConnectionProvider(project: Project): StreamConnectionProvider {
|
||||
return CLanguageServer(project)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package org.gregorybednov.clsp
|
||||
|
||||
import org.jetbrains.plugins.textmate.api.TextMateBundleProvider
|
||||
import org.jetbrains.plugins.textmate.api.TextMateBundleProvider.PluginBundle
|
||||
import kotlin.io.path.Path
|
||||
|
||||
class CTextMateBundleProvider : TextMateBundleProvider {
|
||||
override fun getBundles(): List<PluginBundle> {
|
||||
return listOf(
|
||||
PluginBundle("c/c++", Path("/Users/gregorybednov/Downloads/better-cpp-syntax"))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,18 @@
|
|||
<depends>com.redhat.devtools.lsp4ij</depends>
|
||||
<depends>org.jetbrains.plugins.textmate</depends>
|
||||
|
||||
<actions>
|
||||
<action id="NewCFileAction" class="org.gregorybednov.NewCFileAction" >
|
||||
<add-to-group group-id="NewGroup" relative-to-action="NewFile" anchor="before"/>
|
||||
</action>
|
||||
<action id="NewCppFileAction" class="org.gregorybednov.NewCppFileAction">
|
||||
<add-to-group group-id="NewGroup" relative-to-action="NewFile" anchor="before"/>
|
||||
</action>
|
||||
</actions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<internalFileTemplate name="DefaultTemplate.c"/>
|
||||
<internalFileTemplate name="DefaultTemplate.cpp"/>
|
||||
<notificationGroup id="C/C++ notifications"
|
||||
displayType="BALLOON" />
|
||||
<fileType
|
||||
|
|
@ -20,7 +31,6 @@
|
|||
fieldName="INSTANCE"
|
||||
implementationClass="org.gregorybednov.clsp.CFileType"/>
|
||||
|
||||
<!-- F*** $YourFileLanguage!!!!! I spent f**ing week trying to understand what's wrong!!!-->
|
||||
<editorHighlighterProvider
|
||||
filetype="C File"
|
||||
implementationClass="org.jetbrains.plugins.textmate.language.syntax.highlighting.TextMateEditorHighlighterProvider" />
|
||||
|
|
@ -42,9 +52,6 @@
|
|||
<lang.syntaxHighlighterFactory
|
||||
language="C++"
|
||||
implementationClass="org.jetbrains.plugins.textmate.language.syntax.highlighting.TextMateSyntaxHighlighterFactory" />
|
||||
|
||||
|
||||
<textmate.bundleProvider implementation="org.gregorybednov.clsp.CTextMateBundleProvider"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="com.redhat.devtools.lsp4ij">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
\#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Hello world");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
\#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello world";
|
||||
return 0;
|
||||
}
|
||||
38
src/main/resources/icons/clogo.svg
Normal file
38
src/main/resources/icons/clogo.svg
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 38.000089 42.000031"
|
||||
width="16"
|
||||
height="16"
|
||||
version="1.1"
|
||||
id="svg10"
|
||||
>
|
||||
<defs
|
||||
id="defs14" />
|
||||
<path
|
||||
fill="#283593"
|
||||
fill-rule="evenodd"
|
||||
d="m 17.903,0.28628166 c 0.679,-0.381 1.515,-0.381 2.193,0 C 23.451,2.1692817 33.547,7.8372817 36.903,9.7202817 37.582,10.100282 38,10.804282 38,11.566282 c 0,3.766 0,15.101 0,18.867 0,0.762 -0.418,1.466 -1.097,1.847 -3.355,1.883 -13.451,7.551 -16.807,9.434 -0.679,0.381 -1.515,0.381 -2.193,0 -3.355,-1.883 -13.451,-7.551 -16.807,-9.434 -0.678,-0.381 -1.096,-1.084 -1.096,-1.846 0,-3.766 0,-15.101 0,-18.867 0,-0.762 0.418,-1.466 1.097,-1.8470003 3.354,-1.883 13.452,-7.551 16.806,-9.43400004 z"
|
||||
clip-rule="evenodd"
|
||||
id="path2"
|
||||
style="fill:#004482;fill-opacity:1" />
|
||||
<path
|
||||
fill="#5c6bc0"
|
||||
fill-rule="evenodd"
|
||||
d="m 0.304,31.404282 c -0.266,-0.356 -0.304,-0.694 -0.304,-1.149 0,-3.744 0,-15.014 0,-18.759 0,-0.758 0.417,-1.458 1.094,-1.8360003 3.343,-1.872 13.405,-7.507 16.748,-9.38000004 0.677,-0.379 1.594,-0.371 2.271,0.008 3.343,1.87200004 13.371,7.45900004 16.714,9.33100004 0.27,0.152 0.476,0.335 0.66,0.5760003 z"
|
||||
clip-rule="evenodd"
|
||||
id="path4"
|
||||
style="fill:#659ad2;fill-opacity:1" />
|
||||
<path
|
||||
fill="#ffffff"
|
||||
fill-rule="evenodd"
|
||||
d="m 19,7.0002817 c 7.727,0 14,6.2730003 14,14.0000003 0,7.727 -6.273,14 -14,14 -7.727,0 -14,-6.273 -14,-14 0,-7.727 6.273,-14.0000003 14,-14.0000003 z m 0,7.0000003 c 3.863,0 7,3.136 7,7 0,3.863 -3.137,7 -7,7 -3.863,0 -7,-3.137 -7,-7 0,-3.864 3.136,-7 7,-7 z"
|
||||
clip-rule="evenodd"
|
||||
id="path6" />
|
||||
<path
|
||||
fill="#3949ab"
|
||||
fill-rule="evenodd"
|
||||
d="m 37.485,10.205282 c 0.516,0.483 0.506,1.211 0.506,1.784 0,3.795 -0.032,14.589 0.009,18.384 0.004,0.396 -0.127,0.813 -0.323,1.127 l -19.084,-10.5 z"
|
||||
clip-rule="evenodd"
|
||||
id="path8"
|
||||
style="fill:#00599c;fill-opacity:1" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
|
|
@ -4,20 +4,20 @@
|
|||
width="16" height="16" viewBox="0 0 306 344.35" enable-background="new 0 0 306 344.35" xml:space="preserve">
|
||||
<path fill="#00599C" d="M302.107,258.262c2.401-4.159,3.893-8.845,3.893-13.053V99.14c0-4.208-1.49-8.893-3.892-13.052L153,172.175
|
||||
L302.107,258.262z"/>
|
||||
<path fill="#004482" d="M166.25,341.193l126.5-73.034c3.644-2.104,6.956-5.737,9.357-9.897L153,172.175L3.893,258.263
|
||||
<path fill="#004482" d="M166.25,341.193l126.5-73.034c3.644-2.104,6.956-5.737,9.357-9.897L153,172.175L3.893,258.263
|
||||
c2.401,4.159,5.714,7.793,9.357,9.896l126.5,73.034C147.037,345.401,158.963,345.401,166.25,341.193z"/>
|
||||
<path fill="#659AD2" d="M302.108,86.087c-2.402-4.16-5.715-7.793-9.358-9.897L166.25,3.156c-7.287-4.208-19.213-4.208-26.5,0
|
||||
<path fill="#659AD2" d="M302.108,86.087c-2.402-4.16-5.715-7.793-9.358-9.897L166.25,3.156c-7.287-4.208-19.213-4.208-26.5,0
|
||||
L13.25,76.19C5.962,80.397,0,90.725,0,99.14v146.069c0,4.208,1.491,8.894,3.893,13.053L153,172.175L302.108,86.087z"/>
|
||||
<g>
|
||||
<g>
|
||||
<path fill="#FFFFFF" d="M153,274.175c-56.243,0-102-45.757-102-102s45.757-102,102-102c36.292,0,70.139,19.53,88.331,50.968
|
||||
l-44.143,25.544c-9.105-15.736-26.038-25.512-44.188-25.512c-28.122,0-51,22.878-51,51c0,28.121,22.878,51,51,51
|
||||
c18.152,0,35.085-9.776,44.191-25.515l44.143,25.543C223.142,254.644,189.294,274.175,153,274.175z"/>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<polygon fill="#FFFFFF" points="255,166.508 243.666,166.508 243.666,155.175 232.334,155.175 232.334,166.508 221,166.508
|
||||
221,177.841 232.334,177.841 232.334,189.175 243.666,189.175 243.666,177.841 255,177.841 "/>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<polygon fill="#FFFFFF" points="297.5,166.508 274.834,166.508 263.5,166.508
|
||||
263.5,177.841 286.166,177.841 297.5,177.841"/>
|
||||
</g>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Loading…
Add table
Add a link
Reference in a new issue