Skip to content

Commit

Permalink
Import project from romolo
Browse files Browse the repository at this point in the history
  • Loading branch information
aarcangeli committed Dec 29, 2022
1 parent 3470671 commit baabe92
Show file tree
Hide file tree
Showing 34 changed files with 1,658 additions and 81 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
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
21 changes: 21 additions & 0 deletions LICENSE
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.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ platformVersion = 2021.3.3

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins =
platformPlugins = org.jetbrains.plugins.yaml

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 7.5.1
Expand Down
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;
}
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;
}

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"
}
}
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
}
Loading

0 comments on commit baabe92

Please sign in to comment.