dschwen / switch-header-source

Quick switching between C/C++ header and source files
MIT License
13 stars 49 forks source link

Not working since update. #22

Closed KuddLim closed 6 years ago

KuddLim commented 6 years ago

'switch-header-source' is not working since last updates.

I am not sure which version causes problem.. But when I tested with v0.22, it worked well.

I did some digging and I guess function switchNext is not working properly.

Test environment:

switch: (step) ->

Check if the active item is a text editor

editor = atom.workspace.getActiveTextEditor()
return unless editor?

# full path of the current file
filePath = editor.getPath()
# get the base name of the current file (if it matched the fileRegexp)
key = @getKey filePath
if key   **=> key is /path/to/test.cpp**
  # get the list of matching files from the switchMap
  entry = @switchMap.get key   **=> entry has '/path/to/test.cpp', '/path/to/test.h'**
  if entry
    # find the current file's index in the entry..
    index = entry.indexOf filePath   **=> index is -1**
    if index >= 0

index is -1 so nothing happened.

dschwen commented 6 years ago

Which OS are you on (ah I see, from the shortcut it must be Linux)? Are you sure about the value of key? It should be test.cpp! Without the path. filePath should have the full path, and it should be found in the array. It is right there.

I can test this on Linux tonight.

dschwen commented 6 years ago

I'm having trouble replicating this. When I follow your steps it switches to test.h just as expected :-/

KuddLim commented 6 years ago

Thank you for your reply.

Try this,

  1. make a directory and place some headers and sources with terminal. (or anything except atom)
  2. run atom and open directory created in step 1.
  3. open a file and press Alt-o. It works well at this step.
  4. make another directory and place some headers and sources with terminal. (like step 1)
  5. open a file created in step 4
  6. press Alt-o. It is not working at this step.

I guess swithMap is built when atom project (folder) is loaded. So, when I open some file outside this directory, I cannot switch header/source.

In addition, I guess step 1~3 not works when the directory is within symbolic link.. Could you check this too?

dschwen commented 6 years ago

I can confirm the symbolic link issue

filePath = "/home/daniel/Programs/switch-header-source/test/here/test/test.h"
key = test
entry = ["/home/daniel/Programs/switch-header-source/test/in/here/test/test.cpp", "/home/daniel/Programs/switch-header-source/test/in/here/test/test.h"]

The entry array contains the fully resolved path, while the filePath contains the symbolic links. That should be easy to fix.

dschwen commented 6 years ago

I'm closing this in favor of the separate more detailed issues #23 and #24