瀏覽代碼

make -D old-error-format deal with display completion being sent in bytes instead of chars

Nicolas Cannasse 8 年之前
父節點
當前提交
3a3c8151ed
共有 2 個文件被更改,包括 13 次插入3 次删除
  1. 11 1
      src/compiler/main.ml
  2. 2 2
      src/syntax/lexer.ml

+ 11 - 1
src/compiler/main.ml

@@ -748,7 +748,17 @@ try
 		com.warning <- if com.display.dms_error_policy = EPCollect then (fun s p -> add_diagnostics_message com s p DisplayTypes.DiagnosticsSeverity.Warning) else message ctx;
 		com.error <- error ctx;
 	end;
-	Lexer.zero_based_columns := Common.defined com Define.OldErrorFormat;
+	Lexer.old_format := Common.defined com Define.OldErrorFormat;
+	if !Lexer.old_format && !Parser.resume_display <> null_pos then begin
+		let p = !Parser.resume_display in
+		(* convert byte position to utf8 position *)
+		try
+			let content = Std.input_file ~bin:true (Path.get_real_path p.pfile) in
+			let pos = UTF8.length (String.sub content 0 p.pmin) in
+			Parser.resume_display := { p with pmin = pos; pmax = pos }
+		with _ ->
+			() (* ignore *)
+	end;
 	DisplayOutput.process_display_file com classes;
 	let ext = Initialize.initialize_target ctx com classes in
 	(* if we are at the last compilation step, allow all packages accesses - in case of macros or opening another project file *)

+ 2 - 2
src/syntax/lexer.ml

@@ -196,13 +196,13 @@ let get_error_line p =
 	let l, _ = find_pos p in
 	l
 
-let zero_based_columns = ref false
+let old_format = ref false
 
 let get_pos_coords p =
 	let file = find_file p.pfile in
 	let l1, p1 = find_line p.pmin file in
 	let l2, p2 = find_line p.pmax file in
-	if !zero_based_columns then
+	if !old_format then
 		l1, p1, l2, p2
 	else
 		l1, p1+1, l2, p2+1