Skip to content

Commit

Permalink
fmt: don't change paths when formatting imports (#21148)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Mar 30, 2024
1 parent a015824 commit 6f99796
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/v_apps_and_modules_compile_ci.yml
Expand Up @@ -107,7 +107,7 @@ jobs:
# v -cc gcc run /tmp/gitly/tests/first_run.v
# # /tmp/gitly/gitly -ci_run
- name: Build V Language Server (v-analyzer) vlang/v-analyzer
- name: Build vlang/v-analyzer
run: |
echo "Clone v-analyzer"
.github/workflows/retry.sh git clone --depth=1 --filter=blob:none --recursive --shallow-submodules https://github.com/vlang/v-analyzer /tmp/v-analyzer
Expand All @@ -119,6 +119,18 @@ jobs:
echo "Build v-analyzer release"
v build.vsh release
- name: Format vlang/v-analyzer
run: |
cd /tmp/v-analyzer
set +e
v fmt -c .
exit_code=$?
if [[ $exit_code -ne 0 && $exit_code -ne 5 ]]; then
# Don't fail on on internal errors
v fmt -diff .
exit 1
fi
- name: Build vlang/go2v
run: |
echo "Clone Go2V"
Expand Down
9 changes: 1 addition & 8 deletions vlib/v/fmt/fmt.v
Expand Up @@ -372,13 +372,6 @@ pub fn (mut f Fmt) imports(imports []ast.Import) {
}

pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
mut imp_res := imp.source_name
if imp.mod.starts_with('src.') || (imp.mod.contains('src.') && imp.mod != imp.source_name) {
imp_after_src := imp.mod.all_after('src.')
if imp.source_name.all_after('src.') == imp_after_src {
imp_res = imp_after_src
}
}
// Format / remove unused selective import symbols
// E.g.: `import foo { Foo }` || `import foo as f { Foo }`
has_alias := imp.alias != imp.source_name.all_after_last('.')
Expand All @@ -392,7 +385,7 @@ pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
' {\n\t' + syms.join(',\n\t') + ',\n}'
}
}
return '${imp_res}${suffix}'
return '${imp.source_name}${suffix}'
}

//=== Node helpers ===//
Expand Down

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion vlib/v/fmt/testdata/vmodules/src_import/src/a/ab/ab.v

This file was deleted.

Empty file.

0 comments on commit 6f99796

Please sign in to comment.