ale icon indicating copy to clipboard operation
ale copied to clipboard

ALE omnifunc completion re-inserts previously completed text on subsequent suggestions

Open pbnj opened this issue 3 years ago • 0 comments

Information

VIM version

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jul 25 2022 08:23:04)
macOS version - arm64
Included patches: 1-65
Compiled by GitHub Actions

Operating System: macOS 12.5 - M1 chip

What went wrong

Given the following terraform file (| indicates cursor location):

data "aws_iam_policy_document" "foo" {
  # ... irrelevant
}

resource "aws_iam_policy" "foo" {
  name = "foo"
  assume_role_policy = |
}

When I type:

data.aws_<C-x><C-o>

I get the expected suggestions (i.e. aws_iam_policy_document.foo), so I select it with <C-n> or <C-p>.

The current state of the buffer is (| indicates cursor position):

data "aws_iam_policy_document" "foo" {
  # ... irrelevant
}

resource "aws_iam_policy" "foo" {
  name = "foo"
  assume_role_policy = data.aws_iam_policy_document.foo|
}

Then, I proceed to type .<C-x><C-o> and I get the following expected suggestions:

data.aws_iam_policy.foo.id
data.aws_iam_policy.foo.json
data.aws_iam_policy.foo.statement
data.aws_iam_policy.foo.version

Now, when I cycle through these suggestions to select the desired one, the full suggestion is re-inserted instead of the last property that I am completing.

So the state of the buffer incorrectly becomes:

data "aws_iam_policy_document" "foo" {
  # ... irrelevant
}

resource "aws_iam_policy" "foo" {
  name = "foo"
  assume_role_policy = data.aws_iam_policy_document.foo.data.aws_iam_policy_document.foo.json|
}

When the expected state should be:

data "aws_iam_policy_document" "foo" {
  # ... irrelevant
}

resource "aws_iam_policy" "foo" {
  name = "foo"
  assume_role_policy = data.aws_iam_policy_document.foo.json|
}

Demo

demo

Reproducing the bug

Pre-reqs

  1. terraform
  2. terraform-ls

Steps

  1. Create a test directory mkdir -p test
  2. In main.tf file, paste the following:
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "4.9.0"
    }
  }
}

provider "aws" {}

data "aws_iam_policy_document" "foo" {
  statement {}
}

resource "aws_iam_policy" "foo" {
  name   = "foo"
  policy = ""
}

# replace the empty string above with and start typing (`|` indicates cursor position):
#   data.|
# Omnifunc should suggest `data.aws_iam_policy_document.foo` 
# Select that and proceed to type `.`, so current buffer state should be:
#   data.aws_iam_policy_document.foo.|
# Omnifunc should suggest:
#   data.aws_iam_policy_document.foo.id
#   data.aws_iam_policy_document.foo.json
#   data.aws_iam_policy_document.foo.statement
#   data.aws_iam_policy_document.foo.version
# Select the `json` one
#
# Result will incorrectly be:
#   data.aws_iam_policy_document.foo.data.aws_iam_policy_document.foo.json
#
# Result should be:
#   data.aws_iam_policy_document.foo.json

:ALEInfo

 Current Filetype: terraform
Available Linters: ['checkov', 'terraform', 'terraform_ls', 'terraform_lsp', 'tflint']
  Enabled Linters: ['checkov', 'terraform', 'terraform_ls', 'terraform_lsp', 'tflint']
  Ignored Linters: []
 Suggested Fixers: 
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'terraform' - Fix tf and hcl files with terraform fmt.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
 Linter Variables:

let g:ale_terraform_checkov_executable = 'checkov'
let g:ale_terraform_checkov_options = ''
let g:ale_terraform_langserver_executable = 'terraform-lsp'
let g:ale_terraform_langserver_options = ''
let g:ale_terraform_ls_executable = 'terraform-ls'
let g:ale_terraform_ls_options = ''
let g:ale_terraform_terraform_executable = 'terraform'
let g:ale_terraform_tflint_executable = 'tflint'
let g:ale_terraform_tflint_options = ''
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = 100
let g:ale_completion_enabled = 1
let g:ale_completion_max_suggestions = 50
let g:ale_disable_lsp = 0
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_fixers = {'*': ['remove_trailing_lines', 'trim_whitespace']}
let b:ale_fixers = ['terraform']
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(executable check - failure) terraform-lsp
(executable check - failure) terraform-lsp
(executable check - failure) checkov
(started) ['/opt/homebrew/bin/bash', '-c', '''terraform'' validate -no-color -json  < ''/var/folders/3k/wtcywxr96gnc3xpysznpsf440000gn/T/vDVU3AB/233/role-[REDACTED].tf''']
(executable check - failure) terraform-lsp
(finished - exit code 0) ['/opt/homebrew/bin/bash', '-c', 'cd ''/Users/peterbenjamin/Projects/[REDACTED]'' && ''tflint'' -f json < ''/var/folders/3k/wtcywxr96gnc3xpysznpsf440000gn/T/vDVU3AB/234/role-team-eng-searchsegmentation.tf''']

<<<OUTPUT STARTS>>>
{"issues":[],"errors":[]}
<<<OUTPUT ENDS>>>

(executable check - failure) terraform-lsp
(executable check - failure) checkov
(finished - exit code 0) ['/opt/homebrew/bin/bash', '-c', '''terraform'' validate -no-color -json  < ''/var/folders/3k/wtcywxr96gnc3xpysznpsf440000gn/T/vDVU3AB/237/role-[REDACTED].tf''']

<<<OUTPUT STARTS>>>
{
  "format_version": "1.0",
  "valid": true,
  "error_count": 0,
  "warning_count": 0,
  "diagnostics": []
}
<<<OUTPUT ENDS>>>

(executable check - failure) terraform-lsp
(finished - exit code 0) ['/opt/homebrew/bin/bash', '-c', 'cd ''/Users/peterbenjamin/Projects/[REDACTED]'' && ''tflint'' -f json < ''/var/folders/3k/wtcywxr96gnc3xpysznpsf440000gn/T/vDVU3AB/238/role-[REDACTED].tf''']

<<<OUTPUT STARTS>>>
{"issues":[],"errors":[]}
<<<OUTPUT ENDS>>>

(executable check - failure) terraform-lsp
(executable check - failure) terraform-lsp
(executable check - failure) terraform-lsp
(executable check - failure) terraform-lsp
(executable check - failure) terraform-lsp
(executable check - failure) terraform-lsp
(executable check - failure) terraform-lsp
(executable check - failure) terraform-lsp
(executable check - failure) terraform-lsp

pbnj avatar Aug 05 '22 03:08 pbnj