mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
Fix line numbers in functions
This added the function offset *again*, but it's already included in the line for the current file. And yes, I have explicitly tested a function file with a function defined at a later line. Fixes #6350
This commit is contained in:
parent
f36705bb66
commit
662fb3f3d1
@ -484,12 +484,6 @@ int parser_t::get_lineno() const {
|
|||||||
int lineno = -1;
|
int lineno = -1;
|
||||||
if (execution_context) {
|
if (execution_context) {
|
||||||
lineno = execution_context->get_current_line_number();
|
lineno = execution_context->get_current_line_number();
|
||||||
|
|
||||||
// If we are executing a function, we have to add in its offset.
|
|
||||||
const wchar_t *function_name = is_function();
|
|
||||||
if (function_name != nullptr) {
|
|
||||||
lineno += function_get_definition_lineno(function_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return lineno;
|
return lineno;
|
||||||
}
|
}
|
||||||
|
29
tests/checks/line-number.fish
Normal file
29
tests/checks/line-number.fish
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# RUN: %fish %s
|
||||||
|
#
|
||||||
|
# These lines left around because we need the line numbers.
|
||||||
|
# This file in general requires careful editing in the middle, I recommend appending.
|
||||||
|
function t --on-event linenumber
|
||||||
|
status line-number
|
||||||
|
status line-number
|
||||||
|
status line-number
|
||||||
|
end
|
||||||
|
|
||||||
|
emit linenumber
|
||||||
|
# CHECK: 6
|
||||||
|
# CHECK: 7
|
||||||
|
# CHECK: 8
|
||||||
|
|
||||||
|
type --nonexistent-option-so-we-get-a-backtrace
|
||||||
|
# CHECKERR: type: Unknown option '--nonexistent-option-so-we-get-a-backtrace'
|
||||||
|
# CHECKERR: {{.*/type.fish}} (line 7):
|
||||||
|
# CHECKERR: argparse -n type -x t,p,P $options -- $argv
|
||||||
|
# CHECKERR: ^
|
||||||
|
# CHECKERR: in function 'type' with arguments '--nonexistent-option-so-we-get-a-backtrace'
|
||||||
|
# CHECKERR: called on line 16 of file {{.*}}line-number.fish
|
||||||
|
|
||||||
|
function line-number
|
||||||
|
status line-number
|
||||||
|
end
|
||||||
|
|
||||||
|
line-number
|
||||||
|
# CHECK: 25
|
Loading…
x
Reference in New Issue
Block a user