implement build run config
This commit is contained in:
parent
b9d4f976c1
commit
11960e99d0
7 changed files with 246 additions and 2 deletions
1
modules/project/.gitignore
vendored
Normal file
1
modules/project/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
!src/**/build/
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023-2024 FalsePattern
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.falsepattern.zigbrains.project.execution.build;
|
||||||
|
|
||||||
|
import com.falsepattern.zigbrains.project.execution.base.ConfigProducerBase;
|
||||||
|
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ConfigProducerBuild extends ConfigProducerBase<ZigExecConfigBuild> {
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfigurationFactory getConfigurationFactory() {
|
||||||
|
return ConfigTypeBuild.getInstance().getConfigurationFactories()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean setupConfigurationFromContext(@NotNull ZigExecConfigBuild configuration, PsiElement element, String filePath, VirtualFile theFile) {
|
||||||
|
if (ZigLineMarkerBuild.UTILITY_INSTANCE.elementMatches(element)) {
|
||||||
|
configuration.setName("Build");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isConfigurationFromContext(@NotNull ZigExecConfigBuild configuration, String filePath, VirtualFile vFile, PsiElement element) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023-2024 FalsePattern
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.falsepattern.zigbrains.project.execution.build;
|
||||||
|
|
||||||
|
import com.falsepattern.zigbrains.zig.Icons;
|
||||||
|
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||||
|
import com.intellij.execution.configurations.ConfigurationTypeBase;
|
||||||
|
import com.intellij.execution.configurations.ConfigurationTypeUtil;
|
||||||
|
import com.intellij.execution.configurations.RunConfiguration;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import org.jetbrains.annotations.NonNls;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ConfigTypeBuild extends ConfigurationTypeBase {
|
||||||
|
public static final String IDENTIFIER = "ZIGBRAINS_BUILD";
|
||||||
|
|
||||||
|
public static ConfigTypeBuild getInstance() {
|
||||||
|
return ConfigurationTypeUtil.findConfigurationType(ConfigTypeBuild.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigTypeBuild() {
|
||||||
|
super(IDENTIFIER, "ZigBuild", "Zig Build", Icons.ZIG);
|
||||||
|
addFactory(new ConfigFactoryBuild());
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ConfigFactoryBuild extends ConfigurationFactory {
|
||||||
|
public ConfigFactoryBuild() {
|
||||||
|
super(ConfigTypeBuild.this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull RunConfiguration createTemplateConfiguration(@NotNull Project project) {
|
||||||
|
return new ZigExecConfigBuild(project, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull @NonNls String getId() {
|
||||||
|
return IDENTIFIER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023-2024 FalsePattern
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.falsepattern.zigbrains.project.execution.build;
|
||||||
|
|
||||||
|
import com.falsepattern.zigbrains.project.execution.base.ProfileStateBase;
|
||||||
|
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||||
|
|
||||||
|
public class ProfileStateBuild extends ProfileStateBase<ZigExecConfigBuild> {
|
||||||
|
public ProfileStateBuild(ExecutionEnvironment environment, ZigExecConfigBuild configuration) {
|
||||||
|
super(environment, configuration);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,112 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023-2024 FalsePattern
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.falsepattern.zigbrains.project.execution.build;
|
||||||
|
|
||||||
|
import com.falsepattern.zigbrains.project.execution.base.ZigConfigEditor;
|
||||||
|
import com.falsepattern.zigbrains.project.execution.base.ZigExecConfigBase;
|
||||||
|
import com.falsepattern.zigbrains.project.util.ElementUtil;
|
||||||
|
import com.intellij.execution.Executor;
|
||||||
|
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||||
|
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||||
|
import com.intellij.openapi.options.ConfigurationException;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.util.InvalidDataException;
|
||||||
|
import com.intellij.ui.components.JBTextField;
|
||||||
|
import com.intellij.ui.dsl.builder.AlignX;
|
||||||
|
import com.intellij.ui.dsl.builder.AlignY;
|
||||||
|
import com.intellij.ui.dsl.builder.Panel;
|
||||||
|
import lombok.val;
|
||||||
|
import org.apache.groovy.util.Arrays;
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class ZigExecConfigBuild extends ZigExecConfigBase<ZigExecConfigBuild> {
|
||||||
|
public String extraArguments = "";
|
||||||
|
public ZigExecConfigBuild(@NotNull Project project, @NotNull ConfigurationFactory factory) {
|
||||||
|
super(project, factory, "Zig Build");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] buildCommandLineArgs() {
|
||||||
|
val base = new String[]{"build"};
|
||||||
|
if (extraArguments.isBlank()) {
|
||||||
|
return base;
|
||||||
|
} else {
|
||||||
|
return Arrays.concat(base, extraArguments.split(" "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String suggestedName() {
|
||||||
|
return "Build";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Editor getConfigurationEditor() {
|
||||||
|
return new Editor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ProfileStateBuild getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) {
|
||||||
|
return new ProfileStateBuild(environment, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readExternal(@NotNull Element element) throws InvalidDataException {
|
||||||
|
super.readExternal(element);
|
||||||
|
|
||||||
|
val extraArguments = ElementUtil.readString(element, "extraArguments");
|
||||||
|
if (extraArguments != null) {
|
||||||
|
this.extraArguments = extraArguments;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeExternal(@NotNull Element element) {
|
||||||
|
super.writeExternal(element);
|
||||||
|
|
||||||
|
ElementUtil.writeString(element, "extraArguments", extraArguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Editor extends ZigConfigEditor<ZigExecConfigBuild> {
|
||||||
|
private final JBTextField extraArgs = new JBTextField();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void applyEditorTo(@NotNull ZigExecConfigBuild s) throws ConfigurationException {
|
||||||
|
super.applyEditorTo(s);
|
||||||
|
s.extraArguments = extraArgs.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void resetEditorFrom(@NotNull ZigExecConfigBuild s) {
|
||||||
|
super.resetEditorFrom(s);
|
||||||
|
extraArgs.setText(Objects.requireNonNullElse(s.extraArguments, ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void constructPanel(Panel p) {
|
||||||
|
super.constructPanel(p);
|
||||||
|
p.row("Extra arguments", (r) -> {
|
||||||
|
r.cell(extraArgs).resizableColumn().align(AlignX.FILL).align(AlignY.FILL);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.falsepattern.zigbrains.project.execution.linemarker;
|
package com.falsepattern.zigbrains.project.execution.build;
|
||||||
|
|
||||||
import com.falsepattern.zigbrains.project.execution.base.ZigTopLevelLineMarkerBase;
|
import com.falsepattern.zigbrains.project.execution.base.ZigTopLevelLineMarkerBase;
|
||||||
import com.falsepattern.zigbrains.zig.psi.ZigTypes;
|
import com.falsepattern.zigbrains.zig.psi.ZigTypes;
|
||||||
|
@ -26,7 +26,8 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
|
||||||
public class ZigBuildLineMarker extends ZigTopLevelLineMarkerBase {
|
public class ZigLineMarkerBuild extends ZigTopLevelLineMarkerBase {
|
||||||
|
public static final ZigLineMarkerBuild UTILITY_INSTANCE = new ZigLineMarkerBuild();
|
||||||
@Override
|
@Override
|
||||||
protected @Nullable PsiElement getDeclaration(@NotNull PsiElement element) {
|
protected @Nullable PsiElement getDeclaration(@NotNull PsiElement element) {
|
||||||
if (PsiUtil.getElementType(element) != ZigTypes.IDENTIFIER) {
|
if (PsiUtil.getElementType(element) != ZigTypes.IDENTIFIER) {
|
|
@ -27,6 +27,11 @@
|
||||||
<runLineMarkerContributor language="Zig"
|
<runLineMarkerContributor language="Zig"
|
||||||
implementationClass="com.falsepattern.zigbrains.project.execution.test.ZigLineMarkerTest"/>
|
implementationClass="com.falsepattern.zigbrains.project.execution.test.ZigLineMarkerTest"/>
|
||||||
|
|
||||||
|
<configurationType implementation="com.falsepattern.zigbrains.project.execution.build.ConfigTypeBuild"/>
|
||||||
|
<runConfigurationProducer implementation="com.falsepattern.zigbrains.project.execution.build.ConfigProducerBuild"/>
|
||||||
|
<runLineMarkerContributor language="Zig"
|
||||||
|
implementationClass="com.falsepattern.zigbrains.project.execution.build.ZigLineMarkerBuild"/>
|
||||||
|
|
||||||
<directoryProjectGenerator implementation="com.falsepattern.zigbrains.project.platform.ZigDirectoryProjectGenerator"/>
|
<directoryProjectGenerator implementation="com.falsepattern.zigbrains.project.platform.ZigDirectoryProjectGenerator"/>
|
||||||
<newProjectWizard.languageGenerator implementation="com.falsepattern.zigbrains.project.ide.newproject.ZigNewProjectWizard"/>
|
<newProjectWizard.languageGenerator implementation="com.falsepattern.zigbrains.project.ide.newproject.ZigNewProjectWizard"/>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue