Skip to content

Commit

Permalink
Merge pull request #146 from pontem-network/settings-cleanups
Browse files Browse the repository at this point in the history
Settings cleanups, compiler daemon improvements
  • Loading branch information
mkurnikov authored May 14, 2024
2 parents 8d504b8 + 44ded80 commit d41cc8c
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/org/move/cli/externalLinter/CompilerErrors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private fun errorLinesToCompilerMessage(errorLines: List<String>): AptosCompiler
private val FILE_POSITION_RE =
Regex("""┌─ (?<file>(?:\p{Alpha}:)?[0-9a-z_A-Z\-\\./]+):(?<line>[0-9]+):(?<column>[0-9]+)""")
private val ERROR_UNDERLINE_RE =
Regex("""^\s*│\s+-*\s*(?<xors>\^+)""")
Regex("""^\s*│[^\^]*(\^{2,})""")

private fun splitSpans(errorLines: List<String>): List<AptosCompilerSpan> {
val filePositionMatch =
Expand All @@ -50,7 +50,7 @@ private fun splitSpans(errorLines: List<String>): List<AptosCompilerSpan> {
val columnSpan = errorLines
.firstNotNullOfOrNull { ERROR_UNDERLINE_RE.find(it) }
?.groupValues?.get(1)
?.length ?: 0
?.length ?: 1
return listOf(
AptosCompilerSpan(
fileName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,20 @@ class MvExternalLinterConfigurable(val project: Project): BoundConfigurable("Ext
.comment("Adds code highlighting based on the external linter results. May affect the IDE performance")
.bindSelected(state::runOnTheFly)
}
separator()
row {
checkBox("Prevent duplicate errors")
.comment("Skips errors which are implemented by the IDE own analysis engine")
.bindSelected(state::skipErrorsKnownToIde)
}

onApply {
settings.modify {
it.tool = state.tool
it.additionalArguments = state.additionalArguments
// it.channel = state.channel
it.envs = state.envs
it.runOnTheFly = state.runOnTheFly
it.skipErrorsKnownToIde = state.skipErrorsKnownToIde
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MvExternalLinterProjectSettingsService(
// val channel: RustChannel get() = state.channel
val envs: Map<String, String> get() = state.envs
val runOnTheFly: Boolean get() = state.runOnTheFly
val skipErrorsKnownToIde: Boolean get() = state.skipErrorsKnownToIde

class MvExternalLinterProjectSettings: MvProjectSettingsBase<MvExternalLinterProjectSettings>() {
@AffectsHighlighting
Expand All @@ -49,6 +50,8 @@ class MvExternalLinterProjectSettingsService(

@AffectsHighlighting
var runOnTheFly by property(false)
@AffectsHighlighting
var skipErrorsKnownToIde by property(false)

override fun copy(): MvExternalLinterProjectSettings {
val state = MvExternalLinterProjectSettings()
Expand Down
42 changes: 27 additions & 15 deletions src/main/kotlin/org/move/cli/runConfigurations/BlockchainCli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,34 @@ sealed class BlockchainCli {
return Ok(Unit)
}

fun compileProject(
fun checkProject(
project: Project,
owner: Disposable,
args: AptosCompileArgs
): RsResult<ProcessOutput, RsProcessExecutionException.Start> {
// val useClippy = args.linter == ExternalLinter.CLIPPY
// && !checkNeedInstallClippy(project, args.cargoProjectDirectory)
// val checkCommand = if (useClippy) "clippy" else "check"
val arguments = buildList<String> {
// add("--message-format=json")
// add("--all")
// if (args.allTargets && checkSupportForBuildCheckAllTargets()) {
// add("--all-targets")
// }
add("compile")
addAll(ParametersListUtil.parse(args.extraArguments))
}
val extraArguments = ParametersListUtil.parse(args.extraArguments)
val cliArgs =
CliCommandLineArgs(
"move",
arguments,
buildList {
// add("--message-format=json")
add("compile")
if ("--skip-fetch-latest-git-deps" !in extraArguments) {
add("--skip-fetch-latest-git-deps")
}
if (args.isCompilerV2 && "--compiler-version" !in extraArguments) {
add("--compiler-version")
add("v2")
}
if (args.isCompilerV2 && "--language-version" !in extraArguments) {
add("--language-version")
add("2.0")
}
addAll(ParametersListUtil.parse(args.extraArguments))
},
args.moveProjectDirectory,
environmentVariables = EnvironmentVariablesData.create(args.envs, true)
)
Expand Down Expand Up @@ -190,17 +197,22 @@ data class AptosCompileArgs(
val moveProjectDirectory: Path,
val extraArguments: String,
val envs: Map<String, String>,
val isCompilerV2: Boolean,
val skipLatestGitDeps: Boolean,
) {
companion object {
fun forMoveProject(moveProject: MoveProject): AptosCompileArgs {
val settings = moveProject.project.externalLinterSettings
val linterSettings = moveProject.project.externalLinterSettings
val moveSettings = moveProject.project.moveSettings
return AptosCompileArgs(
settings.tool,
linterSettings.tool,
moveProject.workingDirectory,
// moveProject.project.rustSettings.compileAllTargets,
settings.additionalArguments,
linterSettings.additionalArguments,
// settings.channel,
settings.envs
linterSettings.envs,
isCompilerV2 = moveSettings.isCompilerV2,
skipLatestGitDeps = moveSettings.skipFetchLatestGitDeps
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.intellij.openapi.components.StoragePathMacros
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.registry.Registry
import com.intellij.psi.PsiManager
import org.move.cli.runConfigurations.BlockchainCli
import org.move.cli.runConfigurations.BlockchainCli.Aptos
import org.move.cli.runConfigurations.BlockchainCli.Sui
Expand Down Expand Up @@ -65,7 +64,6 @@ class MvProjectSettingsService(
val fetchAptosDeps: Boolean get() = state.fetchAptosDeps

val disableTelemetry: Boolean get() = state.disableTelemetry
val foldSpecs: Boolean get() = state.foldSpecs
val skipFetchLatestGitDeps: Boolean get() = state.skipFetchLatestGitDeps
val dumpStateOnTestFailure: Boolean get() = state.dumpStateOnTestFailure

Expand All @@ -89,7 +87,6 @@ class MvProjectSettingsService(
@AffectsMoveProjectsMetadata
var fetchAptosDeps: Boolean by property(false)

var foldSpecs: Boolean by property(false)
var disableTelemetry: Boolean by property(true)

// change to true here to not annoy the users with constant updates
Expand All @@ -103,14 +100,6 @@ class MvProjectSettingsService(
}
}

override fun notifySettingsChanged(event: SettingsChangedEventBase<MoveProjectSettings>) {
super.notifySettingsChanged(event)

if (event.isChanged(MoveProjectSettings::foldSpecs)) {
PsiManager.getInstance(project).dropPsiCaches()
}
}

override fun createSettingsChangedEvent(
oldEvent: MoveProjectSettings,
newEvent: MoveProjectSettings
Expand All @@ -124,7 +113,7 @@ class MvProjectSettingsService(
companion object {
private val defaultAptosExecType
get() =
if (AptosExecType.isPreCompiledSupportedForThePlatform) AptosExecType.BUNDLED else AptosExecType.LOCAL;
if (AptosExecType.isPreCompiledSupportedForThePlatform) AptosExecType.BUNDLED else AptosExecType.LOCAL
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ class PerProjectMoveConfigurable(val project: Project): BoundConfigurable("Move
.visibleIf(suiRadioButton!!.selected)
}
group {
row {
checkBox("Auto-fold specs in opened files")
.bindSelected(state::foldSpecs)
}
row {
checkBox("Disable telemetry for new Run Configurations")
.bindSelected(state::disableTelemetry)
Expand Down Expand Up @@ -107,7 +103,6 @@ class PerProjectMoveConfigurable(val project: Project): BoundConfigurable("Move
it.localSuiPath = chooseSuiCliPanel.data.localSuiPath

it.blockchain = state.blockchain
it.foldSpecs = state.foldSpecs
it.disableTelemetry = state.disableTelemetry
it.skipFetchLatestGitDeps = state.skipFetchLatestGitDeps
it.dumpStateOnTestFailure = state.dumpStateOnTestFailure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class ChooseAptosCliPanel(versionUpdateListener: (() -> Unit)?): Disposable {

private val downloadPrecompiledBinaryAction = DownloadAptosSDKAction().also {
it.onFinish = { sdk ->
bundledRadioButton.isSelected = false
localRadioButton.isSelected = true
localPathField.text = sdk.targetFile.toString()
updateVersion()
}
Expand Down Expand Up @@ -162,7 +164,6 @@ class ChooseAptosCliPanel(versionUpdateListener: (() -> Unit)?): Disposable {
.resizableColumn()
if (popupActionGroup.childrenCount != 0) {
cell(getAptosActionLink)
.enabledIf(localRadioButton.selected)
}
}
row("--version :") { cell(versionLabel) }
Expand Down
41 changes: 33 additions & 8 deletions src/main/kotlin/org/move/ide/annotator/RsExternalLinterUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import com.intellij.util.messages.MessageBus
import org.apache.commons.lang3.StringEscapeUtils
import org.jetbrains.annotations.Nls
import org.move.cli.externalLinter.RsExternalLinterWidget
import org.move.cli.externalLinter.externalLinterSettings
import org.move.cli.externalLinter.parseCompilerErrors
import org.move.cli.runConfigurations.AptosCompileArgs
import org.move.cli.runConfigurations.BlockchainCli.Aptos
import org.move.ide.annotator.RsExternalLinterFilteredMessage.Companion.filterMessage
import org.move.ide.annotator.RsExternalLinterUtils.TEST_MESSAGE
import org.move.ide.notifications.logOrShowBalloon
import org.move.lang.MoveFile
import org.move.openapiext.ProjectCache
import org.move.openapiext.checkReadAccessAllowed
Expand Down Expand Up @@ -108,7 +110,7 @@ object RsExternalLinterUtils {

override fun run(indicator: ProgressIndicator) {
widget?.inProgress = true
future.complete(check(aptosCli, project, owner, workingDirectory, args))
future.complete(check(aptosCli, project, owner, args))
}

override fun onFinished() {
Expand All @@ -123,21 +125,23 @@ object RsExternalLinterUtils {
aptosCli: Aptos,
project: Project,
owner: Disposable,
workingDirectory: Path,
args: AptosCompileArgs
): RsExternalLinterResult? {
ProgressManager.checkCanceled()
val started = Instant.now()
val output = aptosCli
.compileProject(project, owner, args)
.checkProject(project, owner, args)
.unwrapOrElse { e ->
LOG.error(e)
return null
}
val finish = Instant.now()
ProgressManager.checkCanceled()
if (output.isCancelled) return null
return RsExternalLinterResult(output.stdoutLines, Duration.between(started, finish).toMillis())
return RsExternalLinterResult(
output.stderrLines + output.stdoutLines,
Duration.between(started, finish).toMillis()
)
}

private data class Key(
Expand Down Expand Up @@ -178,8 +182,9 @@ fun MutableList<HighlightInfo>.addHighlightsForFile(
val doc = file.viewProvider.document
?: error("Can't find document for $file in external linter")

val skipIdeErrors = file.project.externalLinterSettings.skipErrorsKnownToIde
val filteredMessages = annotationResult.messages
.mapNotNull { message -> filterMessage(file, doc, message) }
.mapNotNull { message -> filterMessage(file, doc, message, skipIdeErrors) }
// Cargo can duplicate some error messages when `--all-targets` attribute is used
.distinct()
for (message in filteredMessages) {
Expand Down Expand Up @@ -232,15 +237,18 @@ private data class RsExternalLinterFilteredMessage(
// val quickFixes: List<ApplySuggestionFix>
) {
companion object {
private val LOG = logger<RsExternalLinterFilteredMessage>()

fun filterMessage(
file: PsiFile,
document: Document,
message: AptosCompilerMessage
message: AptosCompilerMessage,
skipErrorsKnownToIde: Boolean,
): RsExternalLinterFilteredMessage? {
println(message)
// if (message.message.startsWith("aborting due to") || message.message.startsWith("cannot continue")) {
// return null
// }

val severity = when (message.severityLevel) {
"error" -> HighlightSeverity.ERROR
"warning" -> HighlightSeverity.WEAK_WARNING
Expand All @@ -251,11 +259,28 @@ private data class RsExternalLinterFilteredMessage(
// but they look rather ugly, so just skip them.
val span = message.mainSpan ?: return null

val syntaxErrors = listOf("expected pattern", "unexpected token")
// drop syntax errors
val syntaxErrors = listOf("unexpected token")
// val syntaxErrors = listOf("expected pattern", "unexpected token")
if (syntaxErrors.any { it in span.label.orEmpty() || it in message.message }) {
return null
}

if (skipErrorsKnownToIde) {
val errorsToIgnore = listOf(
// name resolution errors
"unbound variable", "undeclared",
// type errors
"incompatible types", "which expects a value of type",
// too many arguments
"too many arguments", "the function takes",
)
if (errorsToIgnore.any { it in message.message }) {
LOG.logOrShowBalloon("ignore compiler error: ${message.toTestString()}")
return null
}
}

val spanFilePath = PathUtil.toSystemIndependentName(span.filename)
if (!file.virtualFile.path.endsWith(spanFilePath)) return null

Expand Down
11 changes: 4 additions & 7 deletions src/main/kotlin/org/move/ide/folding/MvFoldingBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.elementType
import com.intellij.psi.util.nextLeaf
import org.move.cli.settings.moveSettings
import org.move.lang.MoveFile
import org.move.lang.MoveParserDefinition.Companion.BLOCK_COMMENT
import org.move.lang.MoveParserDefinition.Companion.EOL_DOC_COMMENT
import org.move.lang.MvElementTypes.*
import org.move.lang.core.psi.*
import org.move.lang.core.psi.ext.*

class MvFoldingBuilder : CustomFoldingBuilder(), DumbAware {
class MvFoldingBuilder: CustomFoldingBuilder(), DumbAware {
override fun getLanguagePlaceholderText(node: ASTNode, range: TextRange): String {
when (node.elementType) {
L_BRACE -> return " { "
Expand Down Expand Up @@ -54,17 +53,15 @@ class MvFoldingBuilder : CustomFoldingBuilder(), DumbAware {
PsiTreeUtil.processElements(root) { it.accept(visitor); true }
}

override fun isRegionCollapsedByDefault(node: ASTNode): Boolean {
return node.psi.project.moveSettings.foldSpecs && node.elementType == MODULE_SPEC_BLOCK
|| CodeFoldingSettings.getInstance().isDefaultCollapsedNode(node)
}
override fun isRegionCollapsedByDefault(node: ASTNode): Boolean =
CodeFoldingSettings.getInstance().isDefaultCollapsedNode(node)

private class FoldingVisitor(
private val descriptors: MutableList<FoldingDescriptor>,
private val usesRanges: MutableList<TextRange>,
private val constRanges: MutableList<TextRange>,
private val docCommentRanges: MutableList<TextRange>,
) : MvVisitor() {
): MvVisitor() {

override fun visitCodeBlock(o: MvCodeBlock) = fold(o)
override fun visitScriptBlock(o: MvScriptBlock) = fold(o)
Expand Down
Loading

0 comments on commit d41cc8c

Please sign in to comment.