Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refresh gives double outline

  • Loading branch information...
commit a933e59b744da28ecb25911200e35a4b30ca22ae 1 parent 19b54d5
@jakobc jakobc authored
View
92 org.erlide.core.tests/src/org/erlide/core/ParsingTests.java
@@ -3,7 +3,8 @@
*/
package org.erlide.core;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Collection;
@@ -27,53 +28,54 @@
*/
public class ParsingTests {
- IErlModule module;
+ IErlModule module;
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- final IErlModel model = ErlModelManager.getErlangModel();
- module = model.getModuleFromText(model, "testing", "", null);
- }
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ final IErlModel model = ErlModelManager.getErlangModel();
+ module = model.getModuleFromText(model, "testing", "", null);
+ }
- /**
- * @throws java.lang.Exception
- */
- @After
- public void tearDown() throws Exception {
- module.dispose();
- module = null;
- }
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ module.dispose();
+ module = null;
+ }
- private boolean parse(final String s) {
- final String scannerModuleName = module.getScannerName();
- ErlideScanner.create(scannerModuleName);
- boolean result = false;
- try {
- ErlideScanner.initialScan(scannerModuleName, "", s, false);
- final IErlParser parser = ErlModelManager.getErlangModel()
- .getParser();
- result = parser.parse(module, scannerModuleName, false, "", false);
- } finally {
- ErlideScanner.dispose(scannerModuleName);
- }
- return result;
- }
+ private boolean parse(final String s) {
+ final String scannerModuleName = module.getScannerName();
+ ErlideScanner.create(scannerModuleName);
+ boolean result = false;
+ try {
+ ErlideScanner.initialScan(scannerModuleName, "", s, false);
+ final IErlParser parser = ErlModelManager.getErlangModel()
+ .getParser();
+ result = parser.parse(module, scannerModuleName, false, "", s,
+ false);
+ } finally {
+ ErlideScanner.dispose(scannerModuleName);
+ }
+ return result;
+ }
- @Test
- public void parseCompileDirective() throws ErlModelException {
- final String sourceContent = "[inline,{hipe,[{regalloc,linear_scan}]}]";
- final String source = "-compile(" + sourceContent + ").";
- assertTrue(parse(source));
- final IErlElement attribute = TestingSupport.createErlAttribute(module,
- "compile", null, sourceContent, 0, 50);
- final List<IErlElement> expected = new ArrayList<IErlElement>(1);
- expected.add(attribute);
- final Collection<IErlElement> actual = module.getChildren();
- // assertEquals(expected, actual);
- assertEquals(expected.toString(), actual.toString());
- }
+ @Test
+ public void parseCompileDirective() throws ErlModelException {
+ final String sourceContent = "[inline,{hipe,[{regalloc,linear_scan}]}]";
+ final String source = "-compile(" + sourceContent + ").";
+ assertTrue(parse(source));
+ final IErlElement attribute = TestingSupport.createErlAttribute(module,
+ "compile", null, sourceContent, 0, 50);
+ final List<IErlElement> expected = new ArrayList<IErlElement>(1);
+ expected.add(attribute);
+ final Collection<IErlElement> actual = module.getChildren();
+ // assertEquals(expected, actual);
+ assertEquals(expected.toString(), actual.toString());
+ }
}
View
38 org.erlide.kernel.ide/src/parsing/erlide_noparse.erl
@@ -9,7 +9,7 @@
%%
%% called from Java
--export([initial_parse/5, reparse/2, remove_cache_files/2]).
+-export([initial_parse/6, reparse/2, remove_cache_files/2]).
%% called from Erlang
-export([get_module_refs/4]).
@@ -20,7 +20,7 @@
%% -define(DEBUG, 1).
--define(CACHE_VERSION, 29).
+-define(CACHE_VERSION, 30).
-define(SERVER, erlide_noparse).
-include("erlide.hrl").
@@ -32,17 +32,19 @@
%% API Functions
%%
--spec initial_parse(atom(), string(), string(), boolean(), boolean()) ->
+-spec initial_parse(atom(), string(), string(), string(), boolean(), boolean()) ->
{ok, #model{}, cached | renewing | dont_use_cache, [#ref{}]}
| {error, term(), term()}.
-initial_parse(ScannerName, ModuleFileName, StateDir, UseCache,
+initial_parse(ScannerName, ModuleFileName, InitialText, StateDir, UseCache,
UpdateSearchServer) ->
try
+ ?D({ScannerName, ModuleFileName, UseCache, UpdateSearchServer}),
BaseName = filename:join(StateDir, atom_to_list(ScannerName)),
RefsFileName = BaseName ++ ".refs",
RenewFun = fun(_F) ->
- Tokens = get_tokens(ScannerName, ModuleFileName, StateDir),
+ Tokens = get_tokens(ScannerName, ModuleFileName,
+ InitialText, StateDir),
{Model, Refs} =
do_parse(ScannerName, RefsFileName, Tokens, StateDir,
UpdateSearchServer),
@@ -82,8 +84,14 @@ get_module_refs(ScannerName, ModulePath, StateDir, UpdateSearchServer) ->
{ok, Binary} ->
binary_to_term(Binary);
_ ->
- {ok, _, _, Refs= initial_parse(ScannerName, ModulePath, StateDir,
- true, UpdateSearchServer),
+ InitialText = case file:read_file(ModulePath) of
+ {ok, InitialTextBin} ->
+ binary_to_list(InitialTextBin);
+ _ ->
+ ""
+ end,
+ {ok, _, _, Refs= initial_parse(ScannerName, ModulePath, InitialText,
+ StateDir, true, UpdateSearchServer),
Refs
end.
@@ -102,27 +110,21 @@ remove_cache_files(ScannerName, StateDir) ->
%% Internal functions
%%
-get_tokens(ScannerName, ModuleFileName, StateDir) ->
+get_tokens(ScannerName, ModuleFileName, InitialText, StateDir) ->
case whereis(ScannerName) of
undefined ->
- case file:read_file(ModuleFileName) of
- {ok, InitialTextBin} ->
- InitialText = binary_to_list(InitialTextBin),
- {{_Cached, Module}, _Text} = erlide_scanner:initial_scan(ScannerName, ModuleFileName, InitialText, StateDir, true),
- erlide_scan_model:get_all_tokens(Module);
- {error, Error} ->
- erlide_log:log({"Module not found: ", ModuleFileName, Error}),
- %% not much to do here
- []
- end;
+ {{_Cached, Module}, _Text} = erlide_scanner:initial_scan(ScannerName, ModuleFileName, InitialText, StateDir, true),
+ erlide_scan_model:get_all_tokens(Module);
_ ->
erlide_scanner:get_tokens(ScannerName)
end.
do_parse(ScannerName, RefsFileName, Tokens, StateDir, UpdateSearchServer) ->
{Forms, Comments, References} = erlide_np:parse(Tokens),
+ ?D(Forms),
Model = #model{forms=Forms, comments=Comments},
CompactModel = erlide_np_util:compact_model(Model),
+ ?D(CompactModel),
case StateDir of
"" -> ok;
_ ->
View
65 org.erlide.kernel.ide/src/parsing/erlide_scan_model.erl
@@ -28,7 +28,7 @@
do_scan(ScannerName, InitialText) ->
?D(do_scan),
- Lines = split_lines_w_lengths(InitialText),
+ Lines = erlide_scan_util:split_lines_w_lengths(InitialText),
LineTokens = [scan_line(L) || L <- Lines],
?D([ScannerName]), % , InitialText, LineTokens]),
#module{name=ScannerName, lines=Lines, tokens=LineTokens}.
@@ -56,7 +56,7 @@ get_token_window(Module, Offset, Before, After) ->
{A, B}.
get_token_at(Module, Offset) ->
- case find_line_w_offset(Offset, Module#module.tokens) of
+ case erlide_scan_util:find_line_w_offset(Offset, Module#module.tokens) of
{N, Pos, _Length, Tokens, false} ->
case get_token_at_aux(Tokens, Offset - Pos) of
token_not_found ->
@@ -76,59 +76,16 @@ get_text(#module{lines=Lines}) ->
%% Local Functions
%%
+replace_between(_From, _Length, With, []) ->
+ %% allow for special case when replacing empty set
+ %% (the Length may be 1 from replace_between_lines)
+ With;
replace_between(From, Length, With, In) ->
+ ?D({From, Length, With, In}),
{A, B} = lists:split(From, In),
{_, C} = lists:split(Length, B),
A++With++C.
-%% [{Length, TextIncNL}...]
-split_lines_w_lengths(Text) ->
- split_lines_w_lengths(Text, 0, [], []).
-
-split_lines_w_lengths("", _Length, [], Acc) ->
- lists:reverse(Acc);
-split_lines_w_lengths("", Length, LineAcc, Acc) ->
- lists:reverse(Acc, [{Length, lists:reverse(LineAcc)}]);
-split_lines_w_lengths("\r\n" ++ Text, Length, LineAcc, Acc) ->
- split_lines_w_lengths(Text, 0, [],
- [{Length+2, lists:reverse(LineAcc, "\r\n")} | Acc]);
-split_lines_w_lengths("\n" ++ Text, Length, LineAcc, Acc) ->
- split_lines_w_lengths(Text, 0, [],
- [{Length+1, lists:reverse(LineAcc, "\n")} | Acc]);
-split_lines_w_lengths("\r" ++ Text, Length, LineAcc, Acc) ->
- split_lines_w_lengths(Text, 0, [],
- [{Length+1, lists:reverse(LineAcc, "\r")} | Acc]);
-split_lines_w_lengths([C | Text], Length, LineAcc, Acc) ->
- split_lines_w_lengths(Text, Length+1, [C | LineAcc], Acc).
-
-%% Find a line from [{Length, Line
-
-find_line_w_offset(Offset, Lines) ->
- find_line_w_offset(Offset, 0, 0, Lines).
-
-find_line_w_offset(0, _Pos, _N, []) ->
- {0, 0, 0, "", on_eof};
-find_line_w_offset(_Offset, _Pos, _N, []) ->
- not_found;
-find_line_w_offset(Offset, Pos, N, [{Length, _Line} | Lines]) when Offset >= Pos+Length, Lines =/= [] ->
- find_line_w_offset(Offset, Pos+Length, N+1, Lines);
-find_line_w_offset(Offset, Pos, N, [{Length, Line} |_]) when Pos =< Offset, Offset < Pos + Length ->
- {N, Pos, Length, Line, false};
-find_line_w_offset(Offset, Pos, N, [{Length, Line}]) ->
- case ends_with_newline(Line) orelse Offset > Pos + Length of
- true ->
- {N+1, Pos+Length, 0, "", beyond_eof};
- false ->
- {N, Pos+Length, Length, Line, on_eof}
- end.
-
-ends_with_newline("") -> false;
-ends_with_newline("\n") -> true;
-ends_with_newline("\r") -> true;
-ends_with_newline("\r\n") -> true;
-ends_with_newline([_C | R]) ->
- ends_with_newline(R).
-
%%
%% Nicer version of string:substring/2 accepting out-of-bounds parameters
%% (should be removed eventually)
@@ -154,7 +111,7 @@ substr(Text, Start, Length) ->
string:substr(Text, Start, Length).
replace_between_lines(From, Length, With, Lines) ->
- {LineNo1, Pos1, _Length1, Line1, Beyond1} = find_line_w_offset(From, Lines),
+ {LineNo1, Pos1, _Length1, Line1, Beyond1} = erlide_scan_util:find_line_w_offset(From, Lines),
?D({LineNo1, Pos1, _Length1, Line1, Beyond1}),
FirstPiece = substr(Line1, 1, From-Pos1),
{LineNo2, Pos2, _Length2, Line2, Beyond2} =
@@ -162,7 +119,7 @@ replace_between_lines(From, Length, With, Lines) ->
0 ->
{LineNo1, Pos1, unused, Line1, Beyond1};
_ ->
- find_line_w_offset(From+Length, Lines)
+ erlide_scan_util:find_line_w_offset(From+Length, Lines)
end,
?D({LineNo2, Pos2, _Length2, Line2, Beyond2}),
LastPiece = substr(Line2, From+Length-Pos2+1),
@@ -178,7 +135,7 @@ replace_between_lines(From, Length, With, Lines) ->
_ ->
{FirstPiece++With++LastPiece, LineNo2-LineNo1+1}
end,
- WLines = split_lines_w_lengths(NewText),
+ WLines = erlide_scan_util:split_lines_w_lengths(NewText),
?D(WLines),
{LineNo1, NOldLines, WLines,
replace_between(LineNo1, NOldLines, WLines, Lines)}.
@@ -269,7 +226,7 @@ get_tokens_at(Module, Offset, N) ->
get_tokens_at(_Module, _Offset, 0, Acc) ->
lists:reverse(Acc);
get_tokens_at(Module, Offset, N, Acc0) ->
- case find_line_w_offset(Offset, Module#module.tokens) of
+ case erlide_scan_util:find_line_w_offset(Offset, Module#module.tokens) of
{LineNo, Pos, Length, Tokens, false} ->
{M, Ts} = get_tokens_at_aux(Tokens, Offset - Pos, N),
Acc1 =
View
55 org.erlide.kernel.ide/src/parsing/erlide_scan_util.erl
@@ -0,0 +1,55 @@
+%% @author jakob
+%% @doc @todo Add description to erlide_scan_util.
+
+
+-module(erlide_scan_util).
+
+-export([split_lines_w_lengths/1, find_line_w_offset/2]).
+
+%% [{Length, TextIncNL}...]
+split_lines_w_lengths(Text) ->
+ split_lines_w_lengths(Text, 0, [], []).
+
+split_lines_w_lengths("", _Length, [], Acc) ->
+ lists:reverse(Acc);
+split_lines_w_lengths("", Length, LineAcc, Acc) ->
+ lists:reverse(Acc, [{Length, lists:reverse(LineAcc)}]);
+split_lines_w_lengths("\r\n" ++ Text, Length, LineAcc, Acc) ->
+ split_lines_w_lengths(Text, 0, [],
+ [{Length+2, lists:reverse(LineAcc, "\r\n")} | Acc]);
+split_lines_w_lengths("\n" ++ Text, Length, LineAcc, Acc) ->
+ split_lines_w_lengths(Text, 0, [],
+ [{Length+1, lists:reverse(LineAcc, "\n")} | Acc]);
+split_lines_w_lengths("\r" ++ Text, Length, LineAcc, Acc) ->
+ split_lines_w_lengths(Text, 0, [],
+ [{Length+1, lists:reverse(LineAcc, "\r")} | Acc]);
+split_lines_w_lengths([C | Text], Length, LineAcc, Acc) ->
+ split_lines_w_lengths(Text, Length+1, [C | LineAcc], Acc).
+
+%% Find a line from [{Length, Line
+
+find_line_w_offset(Offset, Lines) ->
+ find_line_w_offset(Offset, 0, 0, Lines).
+
+find_line_w_offset(0, _Pos, _N, []) ->
+ {0, 0, 0, "", on_eof};
+find_line_w_offset(_Offset, _Pos, _N, []) ->
+ not_found;
+find_line_w_offset(Offset, Pos, N, [{Length, _Line} | Lines]) when Offset >= Pos+Length, Lines =/= [] ->
+ find_line_w_offset(Offset, Pos+Length, N+1, Lines);
+find_line_w_offset(Offset, Pos, N, [{Length, Line} |_]) when Pos =< Offset, Offset < Pos + Length ->
+ {N, Pos, Length, Line, false};
+find_line_w_offset(Offset, Pos, N, [{Length, Line}]) ->
+ case ends_with_newline(Line) orelse Offset > Pos + Length of
+ true ->
+ {N+1, Pos+Length, 0, "", beyond_eof};
+ false ->
+ {N, Pos+Length, Length, Line, on_eof}
+ end.
+
+ends_with_newline("") -> false;
+ends_with_newline("\n") -> true;
+ends_with_newline("\r") -> true;
+ends_with_newline("\r\n") -> true;
+ends_with_newline([_C | R]) ->
+ ends_with_newline(R).
View
17 org.erlide.kernel.ide/src/parsing/erlide_scanner.erl
@@ -26,7 +26,7 @@
%% API Functions
%%
--define(CACHE_VERSION, 22).
+-define(CACHE_VERSION, 24).
light_scan_string(B, latin1) ->
S = binary_to_list(B),
@@ -42,13 +42,14 @@ scan_string(L) when is_list(L) ->
erlide_scan_model:get_all_tokens(M).
initial_scan(ScannerName, ModuleFileName, InitialText, StateDir, UseCache) ->
- Text = case InitialText of
- "" ->
- {ok, B} = file:read_file(ModuleFileName),
- binary_to_list(B);
- _ ->
- InitialText
- end,
+%% Text = case InitialText of
+%% "" ->
+%% {ok, B} = file:read_file(ModuleFileName),
+%% binary_to_list(B);
+%% _ ->
+%% InitialText
+%% end,
+ Text = InitialText,
CacheFileName = filename:join(StateDir, atom_to_list(ScannerName) ++ ".scan"),
RenewFun = fun(_F) -> erlide_scan_model:do_scan(ScannerName, Text) end,
{erlide_util:check_and_renew_cached(ModuleFileName, CacheFileName, ?CACHE_VERSION, RenewFun, UseCache), Text}.
View
6 org.erlide.model.api/src/org/erlide/model/erlang/IErlParser.java
@@ -2,8 +2,8 @@
public interface IErlParser {
- public abstract boolean parse(final IErlModule module,
- final String scannerName, final boolean initialParse,
- final String path, boolean updateSearchServer);
+ public abstract boolean parse(final IErlModule module,
+ final String scannerName, final boolean initialParse,
+ final String path, String initialText, boolean updateSearchServer);
}
View
3  org.erlide.model/src/org/erlide/model/internal/erlang/ErlModule.java
@@ -96,7 +96,8 @@ public ErlModule(final IParent parent, final String name,
public boolean internalBuildStructure(final IProgressMonitor pm) {
final IErlParser parser = ErlModelManager.getErlangModel().getParser();
- parsed = parser.parse(this, scannerName, !parsed, getFilePath(), true);
+ parsed = parser.parse(this, scannerName, !parsed, getFilePath(),
+ initialText, true);
return parsed;
}
View
8 org.erlide.model/src/org/erlide/model/internal/erlang/ErlParser.java
@@ -77,7 +77,7 @@ public ErlParser() {
@Override
public boolean parse(final IErlModule module, final String scannerName,
final boolean initialParse, final String path,
- final boolean updateSearchServer) {
+ final String initialText, final boolean updateSearchServer) {
if (module == null) {
return false;
}
@@ -89,7 +89,7 @@ public boolean parse(final IErlModule module, final String scannerName,
final String stateDir = ModelPlugin.getDefault().getStateLocation()
.toString();
res = ErlideNoparse.initialParse(backend, scannerName, path,
- stateDir, updateSearchServer);
+ initialText, stateDir, updateSearchServer);
} else {
res = ErlideNoparse.reparse(backend, scannerName,
updateSearchServer);
@@ -129,6 +129,10 @@ public boolean parse(final IErlModule module, final String scannerName,
module.setComments(moduleComments);
}
fixFunctionComments(module);
+ final String cached = res.arity() > 2 ? ((OtpErlangAtom) res
+ .elementAt(2)).atomValue() : "reparsed";
+ ErlLogger.debug("Parsed %d forms and %d comments (%s)", forms.arity(),
+ comments.arity(), cached);
return forms != null && comments != null;
}
View
7 org.erlide.model/src/org/erlide/model/internal/erlang/ErlideNoparse.java
@@ -19,12 +19,13 @@
public static OtpErlangTuple initialParse(final IRpcSite b,
final String scannerModuleName, final String moduleFileName,
- final String stateDir, final boolean updateRefs) {
+ final String initialText, final String stateDir,
+ final boolean updateRefs) {
OtpErlangTuple res = null;
try {
res = (OtpErlangTuple) b.call(200000, ERLIDE_NOPARSE,
- "initial_parse", "assoo", scannerModuleName,
- moduleFileName, stateDir, true, updateRefs);
+ "initial_parse", "asssoo", scannerModuleName,
+ moduleFileName, initialText, stateDir, true, updateRefs);
} catch (final RpcTimeoutException e) {
ErlLogger.warn(e);
} catch (final RpcException e) {
View
5 org.erlide.model/src/org/erlide/model/internal/erlang/ErlideScanner.java
@@ -100,11 +100,6 @@ public static void replaceText(final String module, final int offset,
final int removeLength, String newText) {
final IRpcSite backend = ModelPlugin.getDefault().getIdeBackend();
try {
- // ErlLogger.debug("replaceText %s %d %d <length %d>", module,
- // offset,
- // removeLength, newTextLen);
- // ErlLogger.debug("replaceText %s %d %d \"%s\"", module, offset,
- // removeLength, newText);
if (newText == null) {
newText = "";
}
View
16 org.erlide.model/src/org/erlide/model/internal/root/ErlModel.java
@@ -67,6 +67,7 @@
import org.erlide.model.util.ResourceUtil;
import org.erlide.util.ErlLogger;
import org.erlide.util.SystemConfiguration;
+import org.erlide.util.Util;
import com.ericsson.otp.erlang.OtpErlangList;
import com.ericsson.otp.erlang.OtpErlangObject;
@@ -718,8 +719,19 @@ public IErlModule createModuleFrom(final IFile file, final IParent parent) {
}
final String name = file.getName();
if (CommonUtils.isErlangFileContentFileName(name)) {
- final IErlModule module = new ErlModule(parent, name, null, file,
- null);
+ String initialText = "";
+ String charset;
+ if (file.isAccessible() && file.isSynchronized(0)) {
+ try {
+ charset = file.getCharset();
+ initialText = Util.getInputStreamAsString(
+ file.getContents(), charset);
+ } catch (final CoreException e) {
+ ErlLogger.warn(e);
+ }
+ }
+ final IErlModule module = new ErlModule(parent, name, initialText,
+ file, null);
if (parent != null) {
parent.addChild(module);
}
View
3  org.erlide.ui/src/org/erlide/ui/editors/internal/reconciling/ErlReconciler.java
@@ -298,6 +298,8 @@ public void documentAboutToBeChanged(final DocumentEvent e) {
*/
@Override
public void documentChanged(final DocumentEvent e) {
+ ErlLogger.debug("documentChanged %d %d %d", e.getOffset(),
+ e.getLength(), e.getText().length());
if (!fThread.isDirty() && fThread.isAlive()) {
if (!fIsAllowedToModifyDocument
&& Thread.currentThread() == fThread) {
@@ -728,6 +730,7 @@ public void reconcileNow() {
}
public void reset() {
+ ErlLogger.debug("reset");
if (fIsIncrementalReconciler) {
synchronized (fDirtyRegionQueue) {
fDirtyRegionQueue.purgeQueue();
Please sign in to comment.
Something went wrong with that request. Please try again.