Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighting sometimes applied to wrong buffer #496

Closed
nickspoons opened this issue Aug 11, 2019 · 5 comments
Closed

Highlighting sometimes applied to wrong buffer #496

nickspoons opened this issue Aug 11, 2019 · 5 comments

Comments

@nickspoons
Copy link
Member

Here is the issue that I am having right now:

  • I get the following error using OmniSharpFindUsages whenever I select a usage in a file that is different than the current file:
Error detected while processing function OmniSharp#proc#vimOutHandler[5]..OmniSharp#stdio#HandleResponse[19]..<SNR>50_FindTextPropertiesRH:
line   35:                                                                                                           
E964: Invalid column number: 7

(I am navigated properly, I just get that error message every time)

  • After jumping to usage in another file and using OmniSharpFindUsages again (in order to go back to the previous file) I get the `-- No lines in buffer --' and have an empty buffer.

Tested on Windows with:

  • VIM 8.1 (Included pathes: 1-1836),
  • two OmniSharp Versions: 1.34.1 and 1.34.2
  • the following simple dotnet project (I use OmniSharpFindUsages on the Class1):
.
├── OmniSharpTest.ConsoleApp
│   ├── Class1.cs
│   ├── OmniSharpTest.ConsoleApp.csproj
│   ├── Program.cs
│   ├── bin
│   └── obj
└── OmniSharpTest.sln

Program.cs

using System;

namespace OmniSharpTest.ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var test = new Class1();
            Console.WriteLine("Hello World!");
        }
    }
}

Class1.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace OmniSharpTest.ConsoleApp
{
    public class Class1
    {
    }
}

.vimrc

syntax on
filetype indent plugin on

let g:OmniSharp_loglevel = 'debug'
let g:OmniSharp_server_stdio = 1
let g:OmniSharp_selector_ui = ''
let g:OmniSharp_timeout = 5 
set completeopt=longest,menuone,preview
let g:OmniSharp_highlight_types = 2

let g:OmniSharp_highlight_groups = {
\ 'csUserIdentifier': [
\   'constant name', 'enum member name', 'field name', 'identifier',
\   'local name', 'parameter name', 'property name', 'static symbol'],
\ 'csUserInterface': ['interface name'],
\ 'csUserMethod': ['extension method name', 'method name'],
\ 'csUserType': ['class name', 'namespace name', 'enum name', 'struct name']
\}

augroup omnisharp_commands
    autocmd!

    " Show type information automatically when the cursor stops moving
    autocmd CursorHold *.cs call OmniSharp#TypeLookupWithoutDocumentation()
 
    " The following commands are contextual, based on the cursor position.
    autocmd FileType cs nnoremap <buffer> gd :OmniSharpGotoDefinition<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>fi :OmniSharpFindImplementations<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>fs :OmniSharpFindSymbol<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>fu :OmniSharpFindUsages<CR>

    " Finds members in the current buffer
    autocmd FileType cs nnoremap <buffer> <Leader>fm :OmniSharpFindMembers<CR>

    autocmd FileType cs nnoremap <buffer> <Leader>fx :OmniSharpFixUsings<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>tt :OmniSharpTypeLookup<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>dc :OmniSharpDocumentation<CR>
    autocmd FileType cs nnoremap <buffer> <C-\> :OmniSharpSignatureHelp<CR>
    autocmd FileType cs inoremap <buffer> <C-\> <C-o>:OmniSharpSignatureHelp<CR>

    " Navigate up and down by method/property/field
    autocmd FileType cs nnoremap <buffer> <C-k> :OmniSharpNavigateUp<CR>
    autocmd FileType cs nnoremap <buffer> <C-j> :OmniSharpNavigateDown<CR>

    " Find all code errors/warnings for the current solution and populate the quickfix window
    autocmd FileType cs nnoremap <buffer> <Leader>cc :OmniSharpGlobalCodeCheck<CR>
augroup END

" Start the omnisharp server for the current solution
nnoremap <Leader>ss :OmniSharpStartServer<CR>
nnoremap <Leader>sp :OmniSharpStopServer<CR>

let mapleader=","

(and no other plugins)

Any ideas about what could've caused that unwanted behavior?

Please let me know if there are any other information that would be useful for you.

EDIT

I forgot to add that this problem does not exist if let g:OmniSharp_highlight_types = 0.

Originally posted by @mszyszko in #468 (comment)

@nickspoons
Copy link
Member Author

@mszyszko I have experienced this error too, but quite rarely, and I haven't been able to reliably reproduce it. Although I haven't seen anything which results in an empty buffer...

So, tell me if I have this right:

  1. you open vim to Program.cs in gvim (?)
  2. you wait for the server to finish loading, and the buffer is highlighted correctly (?)
  3. you navigate to Class1() on line 9 and run :OmniSharpFindUsages
  4. the quickfix list is opened and you select line representing file Class1.cs and hit <CR>
  5. the other file opens in a new buffer
  6. an error message is displayed but highlighting works (?)
  7. you run :OmniSharpFindUsages again, and this time select the Program.cs entry and hit <CR>
  8. an empty buffer is displayed

Is that all correct? What is the output of :echo expand('%:p') in the empty buffer? Is it the correct full filename of your Program.cs file?

@mszyszko
Copy link

You got it 100% correct.

  1. you open vim to Program.cs in gvim (?)

I also tried with vim and got the same results

  1. you wait for the server to finish loading, and the buffer is highlighted correctly (?)

I get an info "Loaded server for OmniSharpTest.sln" and then after maybe 1 second the buffer is highlighted properly

  1. you navigate to Class1() on line 9 and run :OmniSharpFindUsages
  2. the quickfix list is opened and you select line representing file Class1.cs and hit <CR>
  3. the other file opens in a new buffer
  4. an error message is displayed but highlighting works (?)

Hightlighting does work (Buffer gets highlighed almost instantly after opening the buffer)

  1. you run :OmniSharpFindUsages again, and this time select the Program.cs entry and hit <CR>
  2. an empty buffer is displayed

Is that all correct? What is the output of :echo expand('%:p') in the empty buffer? Is it the correct full filename of your Program.cs file?

Output of a :echo expand('%:p') is the path to the Program.cs relative to the :pwd. Details below.

Detailed answer:

A. How I open the file:

>ls

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        11.08.2019    17:38                OmniSharpTest.ConsoleApp
-a----        11.08.2019    13:35           1779 OmniSharpTest.sln

>gvim .\OmniSharpTest.ConsoleApp\Program.cs

B. What is displayed in the quickfix after running :OmniSharpFindUsages on Class1() [line 9]:

OmniSharpTest.ConsoleApp\Class1.cs|7 col 18| public class Class1
.\OmniSharpTest.ConsoleApp\Program.cs|9 col 28| var test = new Class1();

C. I select the first file on that list (well, it is actually already preselected) and I hit <C-R> and the Class1.cs file opens in the other buffer

D. error message gets displayed

Error detected while processing function OmniSharp#proc#vimOutHandler[5]..OmniSharp#stdio#HandleResponse[19]..<SNR>50_FindTextPropertiesRH:
line   35:                                                                                                           
E964: Invalid column number: 7

E. file is properly highlighted

F. I run :OmniSharpFindUsages on ``Class1` [line 7] and I get an emtpy buffer:

.\OmniSharpTest.ConsoleApp\Program.cs --No lines in buffer--

G. I run :echo expand('%:p') on an empty buffer and the result is:

.\OmniSharpTest.ConsoleApp\Program.cs

H. I try:

:e .\OmniSharpTest.ConsoleApp\Program.cs

and I get the correct buffer.

@nickspoons
Copy link
Member Author

OK, I can reproduce it with your .vimrc, and with OmniSharp-vim installed at ~\.vim\pack\omnisharp\start\omnisharp-vim. Now to work out why ...

@nickspoons
Copy link
Member Author

@mszyszko this appears to be a bug in Vim's text properties, I have reported it here: vim/vim#4808

In the mean time, try :set hidden. If you are not used to 'hidden' and don't know about the option, it would be worth reading about it: :h 'hidden'

@nickspoons
Copy link
Member Author

nickspoons commented Aug 13, 2019

@mszyszko Bram has fixed the Vim bug (clearing an unloaded buffer when text property highlights are applied), available in patch 8.1.1844

He has also updated the documentation to make it clear that text properties cannot be applied to unloaded buffers, and when 'hidden' isn't set, buffers are unloaded when the window changes to a different buffer. OmniSharp-vim now handles this situation cleanly.

Note that with :set hidden switching between C# buffers will be smoother, as previous text properties are retained, meaning that the colours are correct as soon as you go back to a previously opened window. With :set nohidden (the Vim default) the text properties are not kept, so OmniSharp-vim has to fetch them every time you open the buffer. Which means the colours flicker if you alternate back and forth between buffers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants