Skip to content

Commit

Permalink
Merge pull request #3307 from Hannah-Sten/logging
Browse files Browse the repository at this point in the history
Include style files in logging indexable roots
  • Loading branch information
PHPirates authored Nov 24, 2023
2 parents c1d90db + 8c0e226 commit d8e7dd5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ fun properties(key: String) = project.findProperty(key).toString()
// Supersedes the use of "buildscript" block and "apply plugin:"
plugins {
id("org.jetbrains.intellij") version "1.16.0"
kotlin("jvm") version ("1.9.0")
kotlin("plugin.serialization") version ("1.9.0")
kotlin("jvm") version ("1.9.20")
kotlin("plugin.serialization") version ("1.9.20")

// Plugin which can check for Gradle dependencies, use the help/dependencyUpdates task.
id("com.github.ben-manes.versions") version "0.50.0"
Expand Down Expand Up @@ -77,6 +77,7 @@ tasks.compileTestKotlin {
dependencies {
// Local dependencies
implementation(files("lib/pretty-tools-JDDE-2.1.0.jar"))
// These lines can sometimes be problematic on Linux, but are required for SumatraPDF
implementation(files("lib/JavaDDE.dll"))
implementation(files("lib/JavaDDEx64.dll"))

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pluginVersion = 0.9.2
pluginVersion = 0.9.3-alpha.1

# Info about build ranges: https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
# Note that an xyz branch corresponds to version 20xy.z and a since build of xyz.*
Expand Down
23 changes: 14 additions & 9 deletions src/nl/hannahsten/texifyidea/index/IndexUtilBase.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nl.hannahsten.texifyidea.index

import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
Expand All @@ -11,6 +10,7 @@ import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.StubIndex
import com.intellij.psi.stubs.StubIndexKey
import com.intellij.refactoring.suggested.createSmartPointer
import nl.hannahsten.texifyidea.util.Log
import nl.hannahsten.texifyidea.util.files.documentClassFileInProject
import nl.hannahsten.texifyidea.util.files.findRootFile
import nl.hannahsten.texifyidea.util.files.referencedFileSet
Expand Down Expand Up @@ -139,9 +139,10 @@ abstract class IndexUtilBase<T : PsiElement>(
try {
return runReadAction { StubIndex.getElements(indexKey, name, project, scope, elementClass) }
}
catch (e: RuntimeExceptionWithAttachments) {
// Ignore, because we've seen it only four times so far (#1375, #1446, #1591, #2086) but I fail to see how this would be a bug in TeXiFy.
if (e.message?.contains("PSI and index do not match") == false) throw e
catch (e: Exception) {
// For some reason, any issue from any plugin that causes an exception will be raised here and will be attributed to TeXiFy, flooding the backlog
// Hence, we just ignore all of them and hope it's not important
Log.warn(e.toString())
}
return emptySet()
}
Expand All @@ -153,12 +154,16 @@ abstract class IndexUtilBase<T : PsiElement>(
* The project instance.
*/
private fun getKeys(project: Project): Array<String> {
return if (!DumbService.isDumb(project) && !project.isDefault) {
runReadAction { StubIndex.getInstance().getAllKeys(indexKey, project).toTypedArray() }
}
else {
emptyArray()
if (!DumbService.isDumb(project) && !project.isDefault) {
try {
return runReadAction { StubIndex.getInstance().getAllKeys(indexKey, project).toTypedArray() }
}
catch (e: Exception) {
// See above
Log.warn(e.toString())
}
}
return emptyArray()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class LatexIndexableSetContributor : IndexableSetContributor() {
// Add source files
val roots = LatexSdkUtil.getSdkSourceRoots(project) { sdk, homePath -> sdk.getDefaultSourcesPath(homePath) }.toMutableSet()
// Check if we possibly need to extract files first
Log.debug("Indexing source roots $roots")
for (root in roots) {
if (root.path.contains("MiKTeX", ignoreCase = true) && !extractedFiles) {
try {
Expand All @@ -50,6 +49,7 @@ class LatexIndexableSetContributor : IndexableSetContributor() {
// Unfortunately, since .sty is a LaTeX file type, these will all be parsed, which will take an enormous amount of time.
// Note that using project-independent getAdditionalRootsToIndex does not fix this
roots.addAll(LatexSdkUtil.getSdkSourceRoots(project) { sdkType, homePath -> sdkType.getDefaultStyleFilesPath(homePath) })
Log.debug("Indexing source roots $roots")

return roots
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiFile
import nl.hannahsten.texifyidea.inspections.InsightGroup
import nl.hannahsten.texifyidea.inspections.TexifyInspectionBase
import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand
import nl.hannahsten.texifyidea.lang.magic.MagicCommentScope
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.util.files.commandsInFile
import nl.hannahsten.texifyidea.util.labels.findLatexAndBibtexLabelStringsInFileSet
import nl.hannahsten.texifyidea.util.parser.firstParentOfType
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.magic.cmd
import nl.hannahsten.texifyidea.util.parser.firstParentOfType
import java.lang.Integer.max
import java.util.*

Expand Down Expand Up @@ -56,7 +58,7 @@ open class LatexUnresolvedReferenceInspection : TexifyInspectionBase() {
if (part == "*") continue

// The cleveref package allows empty items to customize enumerations
if (part.isEmpty() && (command.commandToken.text == "\\cref" || command.commandToken.text == "\\Cref")) continue
if (part.isEmpty() && (command.name == LatexGenericRegularCommand.CREF.cmd || command.name == LatexGenericRegularCommand.CREF_CAPITAL.cmd)) continue

// If there is no label with this required label parameter value
if (!labels.contains(part.trim())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ object LatexPackageLocationCache {
// We cannot just fill the cache on the fly, because then we will also run kpsewhich when the user is still typing a package name, so we will run it once for every letter typed and this is already too expensive.
// We cannot rely on ls-R databases because they are not always populated, and running mktexlsr may run into permission issues.
val executableName = LatexSdkUtil.getExecutableName("kpsewhich", project)
val searchPaths = runCommand(executableName, "-show-path=tex")
cache = runCommand(executableName, "-expand-path", searchPaths ?: ".:")?.split(File.pathSeparator)
val searchPaths = (runCommand(executableName, "-show-path=tex") ?: ".") + File.pathSeparator + (runCommand(executableName, "-show-path=bib") ?: ".")
cache = runCommand(executableName, "-expand-path", searchPaths)?.split(File.pathSeparator)
?.flatMap { LocalFileSystem.getInstance().findFileByPath(it)?.children?.toList() ?: emptyList() }
?.filter { !it.isDirectory }
?.toSet()
Expand Down

0 comments on commit d8e7dd5

Please sign in to comment.