From 202643b7713a11d9d13a170bb423b97eb6b5a3e6 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 20 May 2014 18:31:17 +0200 Subject: [PATCH] init "auto expressions in Coffee" spec init workaround for: https://github.com/wearefractal/gulp-coffee/pull/8 "As of right now, the original file, compiled file, and source map file all have to live in the same location in order for the source map references to be correct." But it is not suitable - we can specify "out" dir as destination and in this case IDEA cannot map source file to vm (because "sources" will be equals to "test.coffee" instead of "../test.coffee"), so, we try to resolve file only by filename --- .../debugger/sourcemap/SourceMap.java | 2 +- .../debugger/sourcemap/SourceResolver.java | 32 +++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) 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]; }