generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3470671
commit baabe92
Showing
34 changed files
with
1,658 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = unset | ||
indent_style = space | ||
indent_size = 2 | ||
ij_continuation_indent_size = 2 | ||
max_line_length = 140 | ||
insert_final_newline = true | ||
|
||
ij_any_else_on_new_line = true | ||
ij_any_catch_on_new_line = true | ||
ij_any_finally_on_new_line = true | ||
ij_any_block_comment_at_first_column = false | ||
ij_any_line_comment_at_first_column = false | ||
ij_javascript_force_semicolon_style = true | ||
ij_javascript_use_semicolon_after_statement = false | ||
ij_formatter_tags_enabled = true | ||
|
||
[*.py] | ||
indent_size = 4 |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Alessandro Arcangeli <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/github/aarcangeli/ideaclangformat/ClangFormatReplacement.java
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,13 @@ | ||
package com.github.aarcangeli.ideaclangformat; | ||
|
||
import javax.xml.bind.annotation.XmlAttribute; | ||
import javax.xml.bind.annotation.XmlValue; | ||
|
||
public class ClangFormatReplacement { | ||
@XmlAttribute | ||
public int offset; | ||
@XmlAttribute | ||
public int length; | ||
@XmlValue | ||
public String value; | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/github/aarcangeli/ideaclangformat/ClangFormatResponse.java
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,40 @@ | ||
package com.github.aarcangeli.ideaclangformat; | ||
|
||
import com.github.aarcangeli.ideaclangformat.exceptions.ClangFormatError; | ||
import com.intellij.openapi.util.NlsSafe; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBException; | ||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
import java.io.StringReader; | ||
import java.util.List; | ||
|
||
@XmlRootElement(name = "replacements") | ||
public class ClangFormatResponse { | ||
static final JAXBContext REPLACEMENTS_CTX; | ||
|
||
static { | ||
try { | ||
REPLACEMENTS_CTX = JAXBContext.newInstance(ClangFormatResponse.class); | ||
} | ||
catch (JAXBException e) { | ||
throw new RuntimeException("Failed to load JAXB context", e); | ||
} | ||
} | ||
|
||
public static ClangFormatResponse unmarshal(@NotNull @NlsSafe String stdout) { | ||
try { | ||
// JAXB closes the InputStream. | ||
return (ClangFormatResponse) REPLACEMENTS_CTX.createUnmarshaller().unmarshal(new StringReader(stdout)); | ||
} | ||
catch (JAXBException e) { | ||
throw new ClangFormatError("Failed to parse clang-format XML replacements\n" + stdout, e); | ||
} | ||
} | ||
|
||
@XmlElement(name = "replacement") | ||
public List<ClangFormatReplacement> replacements; | ||
} | ||
|
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/com/github/aarcangeli/ideaclangformat/ClangFormatExternalFormatProcessor.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,38 @@ | ||
package com.github.aarcangeli.ideaclangformat | ||
|
||
import com.github.aarcangeli.ideaclangformat.services.ClangFormatService | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.progress.ProgressManager | ||
import com.intellij.openapi.util.TextRange | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.psi.codeStyle.ExternalFormatProcessor | ||
|
||
class ClangFormatExternalFormatProcessor : ExternalFormatProcessor { | ||
override fun activeForFile(file: PsiFile): Boolean { | ||
return service<ClangFormatService>().mayBeFormatted(file) | ||
} | ||
|
||
override fun format( | ||
source: PsiFile, | ||
range: TextRange, | ||
canChangeWhiteSpacesOnly: Boolean, | ||
keepLineBreaks: Boolean, | ||
enableBulkUpdate: Boolean | ||
): TextRange? { | ||
val virtualFile = source.originalFile.virtualFile | ||
if (virtualFile != null) { | ||
ProgressManager.checkCanceled() | ||
service<ClangFormatService>().reformatFileSync(source.project, virtualFile) | ||
return range | ||
} | ||
return null | ||
} | ||
|
||
override fun indent(source: PsiFile, lineStartOffset: Int): String? { | ||
return null | ||
} | ||
|
||
override fun getId(): String { | ||
return "aarcangeli.clang-format" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/github/aarcangeli/ideaclangformat/ClangFormatSettings.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,9 @@ | ||
package com.github.aarcangeli.ideaclangformat | ||
|
||
import com.intellij.psi.codeStyle.CodeStyleSettings | ||
import com.intellij.psi.codeStyle.CustomCodeStyleSettings | ||
|
||
class ClangFormatSettings(container: CodeStyleSettings?) : CustomCodeStyleSettings("clang-format", container) { | ||
@JvmField | ||
var ENABLED = true | ||
} |
Oops, something went wrong.