Skip to content

Commit 9635a09

Browse files
committed
chore: lint fix
1 parent f4668ca commit 9635a09

35 files changed

+651
-577
lines changed

server/src/main/kotlin/org/javacs/kt/CompiledFile.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class CompiledFile(
160160
surroundingContent = content.substring(recoveryRange.startOffset, content.length - (parse.text.length - recoveryRange.endOffset))
161161
offset = recoveryRange.startOffset
162162

163-
if (asReference && !((parent as? KtParameter)?.hasValOrVar() ?: true)) {
163+
if (asReference && (parent as? KtParameter)?.hasValOrVar() == false) {
164164
// Prepend 'val' to (e.g. function) parameters
165165
val prefix = "val "
166166
surroundingContent = prefix + surroundingContent

server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ class CompilerClassPath(
149149
fun changedOnDisk(file: Path): Boolean {
150150
val buildScript = isBuildScript(file)
151151
val javaSource = isJavaSource(file)
152-
if (buildScript || javaSource) {
153-
return refresh(updateClassPath = buildScript, updateBuildScriptClassPath = false, updateJavaSourcePath = javaSource)
152+
return if (buildScript || javaSource) {
153+
refresh(updateClassPath = buildScript, updateBuildScriptClassPath = false, updateJavaSourcePath = javaSource)
154154
} else {
155-
return false
155+
false
156156
}
157157
}
158158

server/src/main/kotlin/org/javacs/kt/Configuration.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ import java.nio.file.InvalidPathException
1212
import java.nio.file.Path
1313
import java.nio.file.Paths
1414

15-
public data class SnippetsConfiguration(
15+
data class SnippetsConfiguration(
1616
/** Whether code completion should return VSCode-style snippets. */
1717
var enabled: Boolean = true
1818
)
1919

20-
public data class CodegenConfiguration(
20+
data class CodegenConfiguration(
2121
/** Whether to enable code generation to a temporary build directory for Java interoperability. */
2222
var enabled: Boolean = false
2323
)
2424

25-
public data class CompletionConfiguration(
25+
data class CompletionConfiguration(
2626
val snippets: SnippetsConfiguration = SnippetsConfiguration()
2727
)
2828

29-
public data class DiagnosticsConfiguration(
29+
data class DiagnosticsConfiguration(
3030
/** Whether diagnostics are enabled. */
3131
var enabled: Boolean = true,
3232
/** The minimum severity of enabled diagnostics. */

server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ class KotlinTextDocumentService(
169169
TODO("not implemented")
170170
}
171171

172-
@Suppress("DEPRECATION")
173172
override fun documentSymbol(params: DocumentSymbolParams): CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> = async.compute {
174173
LOG.info("Find symbols in {}", describeURI(params.textDocument.uri))
175174

server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ class KotlinWorkspaceService(
193193
LOG.info("Updated configuration: {}", settings)
194194
}
195195

196-
@Suppress("DEPRECATION")
197196
override fun symbol(params: WorkspaceSymbolParams): CompletableFuture<Either<List<SymbolInformation>, List<WorkspaceSymbol>>> {
198197
val result = workspaceSymbols(params.query, sp)
199198

server/src/main/kotlin/org/javacs/kt/SourceFiles.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package org.javacs.kt
22

33
import com.intellij.openapi.util.text.StringUtil.convertLineSeparators
4-
import com.intellij.lang.java.JavaLanguage
54
import com.intellij.lang.Language
65
import org.jetbrains.kotlin.idea.KotlinLanguage
76
import org.eclipse.lsp4j.TextDocumentContentChangeEvent
87
import org.javacs.kt.util.KotlinLSException
98
import org.javacs.kt.util.filePath
10-
import org.javacs.kt.util.partitionAroundLast
119
import org.javacs.kt.util.describeURIs
1210
import org.javacs.kt.util.describeURI
1311
import java.io.BufferedReader
@@ -17,9 +15,7 @@ import java.io.IOException
1715
import java.io.FileNotFoundException
1816
import java.net.URI
1917
import java.nio.file.FileSystems
20-
import java.nio.file.Files
2118
import java.nio.file.Path
22-
import java.nio.file.Paths
2319

2420
private class SourceVersion(val content: String, val version: Int, val language: Language?, val isTemporary: Boolean)
2521

server/src/main/kotlin/org/javacs/kt/SourcePath.kt

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ class SourcePath(
5353
val isTemporary: Boolean = false, // A temporary source file will not be returned by .all()
5454
var lastSavedFile: KtFile? = null,
5555
) {
56-
val extension: String? = uri.fileExtension ?: "kt" // TODO: Use language?.associatedFileType?.defaultExtension again
56+
val extension: String =
57+
uri.fileExtension ?: "kt" // TODO: Use language?.associatedFileType?.defaultExtension again
5758
val isScript: Boolean = extension == "kts"
5859
val kind: CompilationKind =
59-
if (path?.fileName?.toString()?.endsWith(".gradle.kts") ?: false) CompilationKind.BUILD_SCRIPT
60+
if (path?.fileName?.toString()?.endsWith(".gradle.kts") == true) CompilationKind.BUILD_SCRIPT
6061
else CompilationKind.DEFAULT
6162

6263
fun put(newContent: String) {
@@ -115,25 +116,29 @@ class SourcePath(
115116
}
116117

117118
fun prepareCompiledFile(): CompiledFile =
118-
parseIfChanged().apply { compileIfNull() }.let { doPrepareCompiledFile() }
119+
parseIfChanged().apply { compileIfNull() }.let { doPrepareCompiledFile() }
119120

120121
private fun doPrepareCompiledFile(): CompiledFile =
121-
CompiledFile(content, compiledFile!!, compiledContext!!, module!!, allIncludingThis(), cp, isScript, kind)
122+
CompiledFile(content, compiledFile!!, compiledContext!!, module!!, allIncludingThis(), cp, isScript, kind)
122123

123124
private fun allIncludingThis(): Collection<KtFile> = parseIfChanged().let {
124125
if (isTemporary) (all().asSequence() + sequenceOf(parsed!!)).toList()
125126
else all()
126127
}
127128

128129
// Creates a shallow copy
129-
fun clone(): SourceFile = SourceFile(uri, content, path, parsed, compiledFile, compiledContext, module, language, isTemporary)
130+
fun clone(): SourceFile =
131+
SourceFile(uri, content, path, parsed, compiledFile, compiledContext, module, language, isTemporary)
130132
}
131133

132134
private fun sourceFile(uri: URI): SourceFile {
133135
if (uri !in files) {
134136
// Fallback solution, usually *all* source files
135137
// should be added/opened through SourceFiles
136-
LOG.warn("Requested source file {} is not on source path, this is most likely a bug. Adding it now temporarily...", describeURI(uri))
138+
LOG.warn(
139+
"Requested source file {} is not on source path, this is most likely a bug. Adding it now temporarily...",
140+
describeURI(uri)
141+
)
137142
put(uri, contentProvider.contentOf(uri), null, temporary = true)
138143
}
139144
return files[uri]!!
@@ -182,13 +187,54 @@ class SourcePath(
182187
* Compile the latest version of a file
183188
*/
184189
fun currentVersion(uri: URI): CompiledFile =
185-
sourceFile(uri).apply { compileIfChanged() }.prepareCompiledFile()
190+
sourceFile(uri).apply { compileIfChanged() }.prepareCompiledFile()
186191

187192
/**
188193
* Return whatever is the most-recent already-compiled version of `file`
189194
*/
190195
fun latestCompiledVersion(uri: URI): CompiledFile =
191-
sourceFile(uri).prepareCompiledFile()
196+
sourceFile(uri).prepareCompiledFile()
197+
198+
// Compile changed files
199+
private fun compileAndUpdate(changed: List<SourceFile>, kind: CompilationKind): BindingContext? {
200+
if (changed.isEmpty()) return null
201+
202+
// Get clones of the old files, so we can remove the old declarations from the index
203+
val oldFiles = changed.mapNotNull {
204+
if (it.compiledFile?.text != it.content || it.parsed?.text != it.content) {
205+
it.clone()
206+
} else {
207+
null
208+
}
209+
}
210+
211+
// Parse the files that have changed
212+
val parse = changed.associateWith { it.apply { parseIfChanged() }.parsed!! }
213+
214+
// Get all the files. This will parse them if they changed
215+
val allFiles = all()
216+
beforeCompileCallback.invoke()
217+
val (context, module) = cp.compiler.compileKtFiles(parse.values, allFiles, kind)
218+
219+
// Update cache
220+
for ((f, parsed) in parse) {
221+
parseDataWriteLock.withLock {
222+
if (f.parsed == parsed) {
223+
//only updated if the parsed file didn't change:
224+
f.compiledFile = parsed
225+
f.compiledContext = context
226+
f.module = module
227+
}
228+
}
229+
}
230+
231+
// Only index normal files, not build files
232+
if (kind == CompilationKind.DEFAULT) {
233+
refreshWorkspaceIndexes(oldFiles, parse.keys.toList())
234+
}
235+
236+
return context
237+
}
192238

193239
/**
194240
* Compile changed files
@@ -199,53 +245,13 @@ class SourcePath(
199245
val allChanged = sources.filter { it.content != it.compiledFile?.text }
200246
val (changedBuildScripts, changedSources) = allChanged.partition { it.kind == CompilationKind.BUILD_SCRIPT }
201247

202-
// Compile changed files
203-
fun compileAndUpdate(changed: List<SourceFile>, kind: CompilationKind): BindingContext? {
204-
if (changed.isEmpty()) return null
205-
206-
// Get clones of the old files, so we can remove the old declarations from the index
207-
val oldFiles = changed.mapNotNull {
208-
if (it.compiledFile?.text != it.content || it.parsed?.text != it.content) {
209-
it.clone()
210-
} else {
211-
null
212-
}
213-
}
214-
215-
// Parse the files that have changed
216-
val parse = changed.associateWith { it.apply { parseIfChanged() }.parsed!! }
217-
218-
// Get all the files. This will parse them if they changed
219-
val allFiles = all()
220-
beforeCompileCallback.invoke()
221-
val (context, module) = cp.compiler.compileKtFiles(parse.values, allFiles, kind)
222-
223-
// Update cache
224-
for ((f, parsed) in parse) {
225-
parseDataWriteLock.withLock {
226-
if (f.parsed == parsed) {
227-
//only updated if the parsed file didn't change:
228-
f.compiledFile = parsed
229-
f.compiledContext = context
230-
f.module = module
231-
}
232-
}
233-
}
234-
235-
// Only index normal files, not build files
236-
if (kind == CompilationKind.DEFAULT) {
237-
refreshWorkspaceIndexes(oldFiles, parse.keys.toList())
238-
}
239-
240-
return context
241-
}
242248

243249
val buildScriptsContext = compileAndUpdate(changedBuildScripts, CompilationKind.BUILD_SCRIPT)
244250
val sourcesContext = compileAndUpdate(changedSources, CompilationKind.DEFAULT)
245251

246252
// Combine with past compilations
247-
val same = sources - allChanged
248-
val combined = listOf(buildScriptsContext, sourcesContext).filterNotNull() + same.map { it.compiledContext!! }
253+
val same = sources - allChanged.toSet()
254+
val combined = listOfNotNull(buildScriptsContext, sourcesContext) + same.map { it.compiledContext!! }
249255

250256
return CompositeBindingContext.create(combined)
251257
}
@@ -351,7 +357,7 @@ class SourcePath(
351357
* Get parsed trees for all .kt files on source path
352358
*/
353359
fun all(includeHidden: Boolean = false): Collection<KtFile> =
354-
files.values
355-
.filter { includeHidden || !it.isTemporary }
356-
.map { it.apply { parseIfChanged() }.parsed!! }
360+
files.values
361+
.filter { includeHidden || !it.isTemporary }
362+
.map { it.apply { parseIfChanged() }.parsed!! }
357363
}

server/src/main/kotlin/org/javacs/kt/codeaction/quickfix/AddMissingImportsQuickFix.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import org.javacs.kt.imports.getImportTextEditEntry
1515
class AddMissingImportsQuickFix: QuickFix {
1616
override fun compute(file: CompiledFile, index: SymbolIndex, range: Range, diagnostics: List<Diagnostic>): List<Either<Command, CodeAction>> {
1717
val uri = file.parse.toPath().toUri().toString()
18-
val unresolvedReferences = getUnresolvedReferencesFromDiagnostics(diagnostics)
19-
18+
val unresolvedReferences = getUnresolvedReferencesFromDiagnostics(diagnostics)
19+
2020
return unresolvedReferences.flatMap { diagnostic ->
2121
val diagnosticRange = diagnostic.range
2222
val startCursor = offset(file.content, diagnosticRange.start)
@@ -25,11 +25,11 @@ class AddMissingImportsQuickFix: QuickFix {
2525

2626
getImportAlternatives(symbolName, file.parse, index).map { (importStr, edit) ->
2727
val codeAction = CodeAction()
28-
codeAction.title = "Import ${importStr}"
28+
codeAction.title = "Import $importStr"
2929
codeAction.kind = CodeActionKind.QuickFix
3030
codeAction.diagnostics = listOf(diagnostic)
3131
codeAction.edit = WorkspaceEdit(mapOf(uri to listOf(edit)))
32-
32+
3333
Either.forRight(codeAction)
3434
}
3535
}
@@ -43,7 +43,7 @@ class AddMissingImportsQuickFix: QuickFix {
4343
private fun getImportAlternatives(symbolName: String, file: KtFile, index: SymbolIndex): List<Pair<String, TextEdit>> {
4444
// wildcard matcher to empty string, because we only want to match exactly the symbol itself, not anything extra
4545
val queryResult = index.query(symbolName, suffix = "")
46-
46+
4747
return queryResult
4848
.filter {
4949
it.kind != Symbol.Kind.MODULE &&

server/src/main/kotlin/org/javacs/kt/codeaction/quickfix/ImplementAbstractMembersQuickFix.kt

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either
55
import org.javacs.kt.CompiledFile
66
import org.javacs.kt.index.SymbolIndex
77
import org.javacs.kt.position.offset
8-
import org.javacs.kt.position.position
98
import org.javacs.kt.util.toPath
109
import org.javacs.kt.overridemembers.createFunctionStub
1110
import org.javacs.kt.overridemembers.createVariableStub
@@ -15,30 +14,13 @@ import org.javacs.kt.overridemembers.getNewMembersStartPosition
1514
import org.javacs.kt.overridemembers.getSuperClassTypeProjections
1615
import org.javacs.kt.overridemembers.hasNoBody
1716
import org.javacs.kt.overridemembers.overridesDeclaration
18-
import org.jetbrains.kotlin.descriptors.ClassDescriptor
19-
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
20-
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
2117
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
2218
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
2319
import org.jetbrains.kotlin.descriptors.isInterface
2420
import org.jetbrains.kotlin.descriptors.Modality
25-
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
26-
import org.jetbrains.kotlin.lexer.KtTokens
2721
import org.jetbrains.kotlin.psi.KtClass
28-
import org.jetbrains.kotlin.psi.KtDeclaration
29-
import org.jetbrains.kotlin.psi.KtNamedFunction
30-
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
31-
import org.jetbrains.kotlin.psi.KtSuperTypeListEntry
32-
import org.jetbrains.kotlin.psi.KtTypeArgumentList
33-
import org.jetbrains.kotlin.psi.KtTypeReference
34-
import org.jetbrains.kotlin.psi.psiUtil.containingClass
35-
import org.jetbrains.kotlin.psi.psiUtil.endOffset
36-
import org.jetbrains.kotlin.psi.psiUtil.isAbstract
3722
import org.jetbrains.kotlin.psi.psiUtil.startOffset
3823
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
39-
import org.jetbrains.kotlin.types.KotlinType
40-
import org.jetbrains.kotlin.types.TypeProjection
41-
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
4224

4325
class ImplementAbstractMembersQuickFix : QuickFix {
4426
override fun compute(file: CompiledFile, index: SymbolIndex, range: Range, diagnostics: List<Diagnostic>): List<Either<Command, CodeAction>> {
@@ -47,7 +29,7 @@ class ImplementAbstractMembersQuickFix : QuickFix {
4729
val startCursor = offset(file.content, range.start)
4830
val endCursor = offset(file.content, range.end)
4931
val kotlinDiagnostics = file.compile.diagnostics
50-
32+
5133
// If the client side and the server side diagnostics contain a valid diagnostic for this range.
5234
if (diagnostic != null && anyDiagnosticMatch(kotlinDiagnostics, startCursor, endCursor)) {
5335
// Get the class with the missing members
@@ -97,7 +79,7 @@ private fun getAbstractMembersStubs(file: CompiledFile, kotlinClass: KtClass) =
9779
val descriptor = referenceAtPoint?.second
9880

9981
val classDescriptor = getClassDescriptor(descriptor)
100-
82+
10183
// If the super class is abstract or an interface
10284
if (null != classDescriptor && (classDescriptor.kind.isInterface || classDescriptor.modality == Modality.ABSTRACT)) {
10385
val superClassTypeArguments = getSuperClassTypeProjections(file, it)

0 commit comments

Comments
 (0)