diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/SourceMap.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/SourceMap.java index a48b7c4e3236..0fb0cd1ac45d 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/SourceMap.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/SourceMap.java @@ -56,7 +56,7 @@ public class SourceMap { if (resolver != null) { SourceResolver.Resolver resolverValue = resolver.getValue(); if (resolverValue != null) { - mappings = sourceResolver.findMappings(this, resolverValue); + mappings = sourceResolver.findMappings(sourceFile, this, resolverValue); } } if (mappings == null) { diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/SourceResolver.java b/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/SourceResolver.java index d9b3cd8f8850..d74f590a5ddf 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/SourceResolver.java +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/sourcemap/SourceResolver.java @@ -5,6 +5,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.StandardFileSystems; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.PathUtilRt; import com.intellij.util.Url; import com.intellij.util.UrlImpl; import com.intellij.util.Urls; @@ -28,16 +29,25 @@ public class SourceResolver { // absoluteLocalPathToSourceIndex contains canonical paths too, but this map contains only used (specified in the source map) path private String[] sourceIndexToAbsoluteLocalPath; + // only if rawSource is filename, but not path + private final ObjectIntHashMap nameToSourceIndex; + public SourceResolver(@NotNull List sources, boolean trimFileScheme, @Nullable Url baseFileUrl) { rawSources = sources; canonicalizedSources = new Url[sources.size()]; canonicalizedSourcesMap = SystemInfo.isFileSystemCaseSensitive ? new ObjectIntHashMap(canonicalizedSources.length) : new ObjectIntHashMap(canonicalizedSources.length, Urls.getCaseInsensitiveUrlHashingStrategy()); + nameToSourceIndex = createStringIntMap(-1); for (int i = 0; i < sources.size(); i++) { - Url url = canonicalizeUrl(sources.get(i), baseFileUrl, trimFileScheme, i); + String rawSource = sources.get(i); + Url url = canonicalizeUrl(rawSource, baseFileUrl, trimFileScheme, i); canonicalizedSources[i] = url; canonicalizedSourcesMap.put(url, i); + + if (PathUtilRt.isValidFileName(rawSource)) { + nameToSourceIndex.put(rawSource, i); + } } } @@ -79,9 +89,7 @@ public class SourceResolver { if (file != null) { if (absoluteLocalPathToSourceIndex == null) { // must be linked, on iterate original path must be first - absoluteLocalPathToSourceIndex = SystemInfo.isFileSystemCaseSensitive - ? new ObjectIntHashMap(rawSources.size()) - : new ObjectIntHashMap(rawSources.size(), CaseInsensitiveStringHashingStrategy.INSTANCE); + absoluteLocalPathToSourceIndex = createStringIntMap(rawSources.size()); sourceIndexToAbsoluteLocalPath = new String[rawSources.size()]; } absoluteLocalPathToSourceIndex.put(path, sourceIndex); @@ -95,6 +103,16 @@ public class SourceResolver { return new UrlImpl(baseUrl.getScheme(), baseUrl.getAuthority(), path, null); } + @NotNull + private static ObjectIntHashMap createStringIntMap(int initialCapacity) { + if (initialCapacity == -1) { + initialCapacity = 4; + } + return SystemInfo.isFileSystemCaseSensitive + ? new ObjectIntHashMap(initialCapacity) + : new ObjectIntHashMap(initialCapacity, CaseInsensitiveStringHashingStrategy.INSTANCE); + } + @Nullable public Url getSource(@NotNull MappingEntry entry) { int index = entry.getSource(); @@ -114,12 +132,12 @@ public class SourceResolver { } public interface Resolver { - int resolve(@NotNull ObjectIntHashMap map); + int resolve(@NotNull VirtualFile sourceFile, @NotNull ObjectIntHashMap map, @NotNull ObjectIntHashMap nameToSourceIndex); } @Nullable - public MappingList findMappings(@NotNull SourceMap sourceMap, @NotNull Resolver resolver) { - int index = resolver.resolve(canonicalizedSourcesMap); + public MappingList findMappings(@NotNull VirtualFile sourceFile, @NotNull SourceMap sourceMap, @NotNull Resolver resolver) { + int index = resolver.resolve(sourceFile, canonicalizedSourcesMap, nameToSourceIndex); return index < 0 ? null : sourceMap.sourceIndexToMappings[index]; }