Comments (7)
Hi @dfishburn,
Please note that we have this logic on https://github.com/prettier/vim-prettier/blob/master/plugin/prettier.vim#L14
if exists('g:loaded_prettier')
finish
endif
let g:loaded_prettier = 1
from vim-prettier.
One thing I am not certain on, when you reference a function in the autoload file, whether Vim automatically sources that file first and then calls it or whether it checks if the function exists and does not source it.
I just use that standard pattern in all my files.
from vim-prettier.
Hi @dfishburn
Autoloaded function get evaluated only once and are also lazy loaded. This is a good reference: http://learnvimscriptthehardway.stevelosh.com/chapters/53.html
Some quotes from the above link
:call somefile#Hello()
When you run this command, Vim will behave a bit differently than a normal function call.
If this function has already been loaded, Vim will simply call it normally.
Otherwise Vim will look for a file called autoload/somefile.vim in your ~/.vim directory (and any Pathogen bundles).
If this file exists, Vim will load/source the file. It will then try to call the function normally.
from vim-prettier.
Once again thanks @dfishburn for raising this issue,
Feel free to comment/re-open this issue if you have any further questions or any info around it
from vim-prettier.
Actually from that web link you provided:
Vim already has a definition for example#Hello, so it doesn't need to reload the file, which means:
The code outside the function wasn't run again.
It didn't pick up the changes to the function.
Now run :call example#BadFunction().
You'll see the loading messages again, as well as an error about a nonexistent function.
But now try running :call example#Hello() again. This time you'll see the updated message!
That is the case I am talking about.
Once you reference a different function in the same file, a function that Vim has not used yet, it sources the file again.
Had you not defined all your functions using function!
, you would have seen an error (function already exists) each time you call a different function.
So, for efficiency you do want the finish
guard at the top of that file.
from vim-prettier.
Will look into this later and get back to this issue, in the meantime will leave it open until I can can check on it more in depth
from vim-prettier.
Hi @dfishburn,
In order to debug the above statement I have just performed the following test, edited autoload/prettier.vim
and included on the top the following line:
echom "loading vim-prettier"
Then I did the following steps:
- Opened a new file
- Executed
:Prettier
- Executed
:PrettierCliVersion
- run the command
:messages
to check for the printed messages
outcome:
- "loading vim-prettier" got printed only once regardless of the multiple calls, so the autoload file got only loaded once
If you can provide a working example of that I will be happy to re-open this issue.
from vim-prettier.
Related Issues (20)
- Prettier doesn't work HOT 1
- feature request to disable automatic mappings set by the plugin
- .eslintrc is ignored
- prettier hang on formatting a bigger file
- MacOS Monterey M1 plugin not loaded
- When endOfLine option set to 'crlf', ^M appear at the end of each line
- Prettier: failed to parse buffer — on mixed HTML/PHP file HOT 1
- Formatting on save stop when saving again
- Deletes comments in Ruby files HOT 3
- The same prettier doesn't work correctly on WSL
- plugin didn't work without installing eslint-config-prettier & eslint-plugin-prettier
- Request: check for filetype javascript (not just the .js and .jsx extensions) HOT 1
- Prettier auto format on Save not working. HOT 1
- Why prettier keeps adding warn messages on top of my document? HOT 16
- Deprecated / Unknown options when using Prettier v3 HOT 3
- Keep show warning after save! HOT 1
- Error while resolving package dependencies HOT 3
- Error on manual trigger
- prettier runs with incorrect prettier configuration HOT 2
- Vim-Prettier is using its own defaults, not the defaults from prettier (in my case, trailingComma)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-prettier.