@@ -22,7 +22,7 @@ import java.nio.file.Path
22
22
import java.nio.file.Paths
23
23
import java.util.stream.Collectors
24
24
25
- private class SourceVersion (val content : String , val version : Int , val isTemporary : Boolean )
25
+ private class SourceVersion (val content : String , val version : Int , val language : Language ? , val isTemporary : Boolean )
26
26
27
27
/* *
28
28
* Notify SourcePath whenever a file changes
@@ -36,7 +36,7 @@ private class NotifySourcePath(private val sp: SourcePath) {
36
36
val content = convertLineSeparators(source.content)
37
37
38
38
files[uri] = source
39
- sp.put(uri, content, source.isTemporary)
39
+ sp.put(uri, content, source.language, source. isTemporary)
40
40
}
41
41
42
42
fun remove (uri : URI ) {
@@ -74,7 +74,7 @@ class SourceFiles(
74
74
private val open = mutableSetOf<URI >()
75
75
76
76
fun open (uri : URI , content : String , version : Int ) {
77
- files[uri] = SourceVersion (content, version, isTemporary = ! exclusions.isURIIncluded(uri))
77
+ files[uri] = SourceVersion (content, version, languageOf(uri), isTemporary = ! exclusions.isURIIncluded(uri))
78
78
open.add(uri)
79
79
}
80
80
@@ -110,7 +110,7 @@ class SourceFiles(
110
110
else newText = patch(newText, change)
111
111
}
112
112
113
- files[uri] = SourceVersion (newText, newVersion, existing.isTemporary)
113
+ files[uri] = SourceVersion (newText, newVersion, existing.language, existing. isTemporary)
114
114
}
115
115
}
116
116
@@ -133,7 +133,7 @@ class SourceFiles(
133
133
134
134
private fun readFromDisk (uri : URI , temporary : Boolean ): SourceVersion ? = try {
135
135
val content = contentProvider.contentOf(uri)
136
- SourceVersion (content, - 1 , isTemporary = temporary)
136
+ SourceVersion (content, - 1 , languageOf(uri), isTemporary = temporary)
137
137
} catch (e: FileNotFoundException ) {
138
138
null
139
139
} catch (e: IOException ) {
@@ -144,19 +144,14 @@ class SourceFiles(
144
144
private fun isSource (uri : URI ): Boolean = exclusions.isURIIncluded(uri) && languageOf(uri) != null
145
145
146
146
private fun languageOf (uri : URI ): Language ? {
147
- val path = uri.path
147
+ val fileName = uri.filePath?.fileName?.toString() ? : return null
148
148
return when {
149
- path .endsWith(" .kt" ) || path .endsWith(" .kts" ) -> KotlinLanguage .INSTANCE
150
- path .endsWith(" .java" ) -> JavaLanguage .INSTANCE
149
+ fileName .endsWith(" .kt" ) || fileName .endsWith(" .kts" ) -> KotlinLanguage .INSTANCE
150
+ fileName .endsWith(" .java" ) -> JavaLanguage .INSTANCE
151
151
else -> null
152
152
}
153
153
}
154
154
155
- private fun findSourceFiles (root : Path ): Set <URI > = Files .walk(root)
156
- .map(Path ::toUri)
157
- .filter(this ::isSource)
158
- .collect(Collectors .toSet())
159
-
160
155
fun addWorkspaceRoot (root : Path ) {
161
156
val addSources = findSourceFiles(root)
162
157
@@ -221,6 +216,15 @@ private fun patch(sourceText: String, change: TextDocumentContentChangeEvent): S
221
216
}
222
217
}
223
218
219
+ private fun findSourceFiles (root : Path ): Set <URI > {
220
+ val sourceMatcher = FileSystems .getDefault().getPathMatcher(" glob:*.{kt,kts,java}" )
221
+ val exclusions = SourceExclusions (root)
222
+ return Files .walk(root)
223
+ .filter { exclusions.isPathIncluded(it) && sourceMatcher.matches(it.fileName) }
224
+ .map(Path ::toUri)
225
+ .collect(Collectors .toSet())
226
+ }
227
+
224
228
private fun logAdded (sources : Collection <URI >, rootPath : Path ? ) {
225
229
LOG .info(" Adding {} under {} to source path" , describeURIs(sources), rootPath)
226
230
}
0 commit comments