Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.8k
runtime(ftplugin): make ft-typescript use javascript.vim#17168
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Conversation
Typescript (and JavascriptReact, TypescriptReact) are just super-sets ofJavascript. So to avoid duplication, we should make them sourceft-javascript.
Uh oh!
There was an error while loading.Please reload this page.
@@ -0,0 +1,14 @@ | |||
" Change the :browse e filter to primarily show JavaScript-related files. | |||
if (has("gui_win32")||has("gui_gtk"))&&!exists("b:browsefilter") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This snippet is moved fromjavascript.vim
to here.
I am not sure if it is a good idea to filter Javascript-like files only. Because in web development, we could also use HTML, CSS, EJS beside Javascript.
Not to say that this behavior is not documented (which means it is unexpected to users), so should this be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I am not sure if it is a good idea to filter Javascript-like files only. Because in web development, we could also use HTML, CSS, EJS beside Javascript.
I agree it's useful to include related files, and have a local copy adding HTML and CSS, but it was never clear where to stop with this. It seems reasonable to limit the filters to the actual filetype and utilise the "All Files" filter for anything else.
Are you suggesting the order should be changed to default to "All files"? That's the default behaviour but the filetype plugins have always put that last, I think.
Lines 2509 to 2525 in31b78cc
#ifdefFEAT_BROWSE | |
# ifdefBACKSLASH_IN_FILENAME | |
# defineBROWSE_FILTER_MACROS \ | |
(char_u *)N_("Vim macro files (*.vim)\t*.vim\nAll Files (*.*)\t*.*\n") | |
# defineBROWSE_FILTER_ALL_FILES (char_u *)N_("All Files (*.*)\t*.*\n") | |
# defineBROWSE_FILTER_DEFAULT \ | |
(char_u *)N_("All Files (*.*)\t*.*\nC source (*.c, *.h)\t*.c;*.h\nC++ source (*.cpp, *.hpp)\t*.cpp;*.hpp\nVB code (*.bas, *.frm)\t*.bas;*.frm\nVim files (*.vim, _vimrc, _gvimrc)\t*.vim;_vimrc;_gvimrc\n") | |
# else | |
# defineBROWSE_FILTER_MACROS \ | |
(char_u *)N_("Vim macro files (*.vim)\t*.vim\nAll Files (*)\t*\n") | |
# defineBROWSE_FILTER_ALL_FILES (char_u *)N_("All Files (*)\t*\n") | |
# defineBROWSE_FILTER_DEFAULT \ | |
(char_u *)N_("All Files (*)\t*\nC source (*.c, *.h)\t*.c;*.h\nC++ source (*.cpp, *.hpp)\t*.cpp;*.hpp\nVim files (*.vim, _vimrc, _gvimrc)\t*.vim;_vimrc;_gvimrc\n") | |
# endif | |
# defineBROWSE_SAVE 1 // flag for do_browse() | |
# defineBROWSE_DIR 2 // flag for do_browse() | |
#endif |
Not to say that this behavior is not documented (which means it is unexpected to users), so should this be removed?
I'm not sure what needs to be documented as the filtering is discoverable simply by opening the file dialog. Rather than remove it, I think abrowsefilter
value should be set for all filetypes.
brianhusterApr 23, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I don't have a strong opinion on whether to keep it or remove it or add what, but I think this kind of behavior should be documented and consistent between different filetypes.
I'm not sure what needs to be documented as the filtering is discoverable simply by opening the file dialog.
I would never know what kind of filetypes it filters without trying it several times. That is bad UX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You mean the(has("gui_win32") || has("gui_gtk"))
? Or what exactly should be documented? The browsefilter variable is defined for "Windows, GTK and the Motif UI". But although Motif GUI supports the browsefilter variable, there is no easy way to switch different filters. So restricting it togui_win32
orgui_gtk
makes sense.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
setlocalsuffixesadd+=.ts,.d.ts,.tsx,.js,.jsx,.cjs,.mjs | ||
letb:undo_ftplugin="setl fo< com< cms< sua<" | ||
runtime! ftplugin/javascript.vim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Does it make sense to set the omnifunc from Javascript also for Typescript? Similar for the 'define' option and matchit values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
For what it's worth, I came up with these settings for typescript, but@romainl surely has better founded ideas on their right values
setlocalinclude=^\\s*\\%(import\\|export\\).*\\<from\\>\\s*['\"]\\zs[^'\"\\r\\n]\\+\\ze['\"]\\|\\<require(\\s*['\"]\\zs[^'\"\\r\\n]\\+\\ze['\"]let &l:define='^\s*\('\..'\(export\s\)*\(default\s\)*\(var\|const\|let\|function\|class\|interface\)\s'\..'\|\(public\|private\|protected\|readonly\|static\)\s'\..'\|\(get\s\|set\s\)'\..'\|\(export\sdefault\s\|abstract\sclass\s\)'\..'\|\(async\s\)'\..'\|\(\ze\i\+([^)]*).*{$\)'\..'\)'ifexists('b:match_words')letb:match_words.=','elseletb:match_words=''endifletb:match_words='\<function\>:\<return\>,'\..'\<do\>:\<while\>,'\..'\<switch\>:\<case\>:\<default\>,'\..'\<if\>:\<else\>,'\..'\<try\>:\<catch\>:\<finally\>'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Just stumbled ontohttps://github.com/HerringtonDarkholme/yats.vim/blob/master/ftplugin/typescript.vim#L91 ; an include expression is also useful
brianhusterMay 5, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I also have an includeexpr that can even jump to Node moduleshttps://github.com/brianhuster/dotfiles/blob/main/.config/nvim/after/ftplugin/javascript.vim
But I don't think it will be very useful because of#16707, and alsolanguage server covers this feature well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
language server covers this feature well.
Ctags and Language Servers take you further, but we're here to max out Vim's built-in functionalities. This reminds me ofzzzyxwvut/java-vim#4 (comment) ; even if&include
sometimes breaks ongf
, its principal use is including other files for grepping#16916 (comment)
brianhusterMay 5, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
but we're here to max out Vim's built-in functionalities
Just think how many people use the built-in omnifunc of JavaScript in 2025?
I will not add it to this PR, but if you want to do it for your own PR, you are free to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
noone even did anything, until I did.
That's commendable, keep up the good work
I will not add it to this PR, but if you want to do it for your own PR, you are free to do that.
Okay, one step after another.
brianhusterMay 5, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Btw, a formatexpr forVimscript
andhelp
will be nice, I think these Vim's specific languages need "maximized Vim functionalities" the most.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yes, makes sense, a separate issue. For help.vim, there'sHelpFormatExpr floating around
Since python and other plug-ins sport these as well, how aboutmappings to move between functions |
I see many mappings, I think we should only choose 2 operations and map to But anyway, it's not purpose of this PR, so I think that should be discussed in another issue |
Konfekt commentedApr 21, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Yes, in principle. What confuses me a bit in general is the distinction between navigating between methods |
are you still working on that@brianhuster ? |
I don't abandon this, but it's true that this is not very high in my priority list (since this is just a refactor, not a fix). So anyone can take over this |
thanks and no worries. Take your time, it may just push down in my attention list :) |
Btw, based on the test, it seems that |
Could I put the file |
Uh oh!
There was an error while loading.Please reload this page.
Typescript (and JavascriptReact, TypescriptReact) are just super-sets of Javascript. So to avoid duplication, I think we should make them source ft-javascript.
I would like some reviews from@dkearns@chrisbra