How code completion in GAS works? - google-apps-script

Is there a detailed description on the "rules" of code completion (CC) in GAS..? Sometimes the CC works perfectly even when I move the cursor back in a code line and sometimes it won't work at all even when there are only three lines of code and everything is defined unambiguously.
ss.getActiveSheet(); // If I go back to "ss" and type a period, it will open
// up CC. (Most times.)
ss.getActiveSheet(); // But also sometimes, even after the "getActiveSheet(),"
// when I put a period, nothing happens.
I know that when you copy and paste code, that it messes it up. But in some cases, it just stops working on a script I've been working on for a long time.
So can someone explain the "rules" of CC? That way the behavior can be understood and, in turn, stops people like me from doing something that stops CC for long scripts. It is getting really irritating having to look up methods, especially when chaining.
Thank you.

Related

Why do my Google Sheet custom functions require this weird workaround?

I’m creating custom functions in Google Sheets using their google apps script language. I’ve done my development on a laptop and it seems to work correctly.
However, when I open the sheet on my mobile device (iOS), the cell output for my custom functions get stuck at “Loading…” forever and never load. But I discovered this weird workaround, but I don’t know why it works or if there’s a better way: if I make a small, trivial change to one of the input cells, then close the sheet and reopen, the sheet will be correctly updated.
Note that if I just make a change to a cell, or add/delete a column etc, without closing and reopening, to force an update, it will still get stuck at “Loading…”.
Also note that if I close and reopen the sheet without making any change, it will still get stuck.
Any ideas of what’s going on here, and if there’s a better way to get my custom functions to correctly update without timing out?
I searched online for solutions, couldn’t find anything.
Update: Example sheet located at this link:
https://docs.google.com/spreadsheets/d/12nm9EwuzqaN0jYUv75CquMhrcUGlVsmEPFoWd92yuWo/edit
Look at the “SeasonTest” tab, cell AS5. On a mobile device it always shows “Loading…” (unless the above workaround is used), but works fine on a desktop

Google Apps Script doesn't show the methods when coding

Firstly, let me say that I am Spanish so my English is not so good, so please be patient if you find it difficult to understand what I am to say.
Having said that, the problem I have when using Google Apps Script is that the kind of window that is being opened when coding isn't work.
For instance: If I type.... var doc = documentapp. nothing happens, that is, the kind of windows that shows the different methods doesn't even try to open, nothing happens
To help you understand the problem I have, I attached a picture with "what should happen" when coding...
I am in despair.. I don't know what is happening.
If you see the picture, when docfile. is typed a windows is open with different methods, like GetEditors and so on..
Well, that the problem I have, that doesn't happen to me when typing code.
Google Apps Script doesn't show the methods when coding
This is an auxiliary feature indicating you that something is not correct in your code
In your particular case: You misspelled DocumentApp (case sensitivity is important in Apps Script, so documentapp is wrong)
After you fix the typing mistake, the methods will be shown correctly after the . - unless you have some other mistake somewhere else in your code

GoogleAppsScript - customfunction completion works randomly

For a few days I've tried to understand why the auto-completion (in the sheet) is working for my customfunction in one Google Sheet and not in another one.
I even copied/pasted the code in the 2nd .gs but no in the second Spreadsheet I can only see original built-in functions.
I did put the #customfunction in my JSdoc of course.
You can see my 2 screenshots.
I've tried a lot of things around casing and spaces and checked every differences between the 2 sheets.
There is none. I'm out of ideas. Please help me figure it out!
Please note that the function workfs perfectly if I enter the formula manually 'till the end.

VS 2015 Razor Autocomplete/Intellisense dropdown hides immediately after dropdown

In VS 2015, only when in Razor (.cshtml) files, roughly half of the time the autocomplete/suggestion list/intellisense doesn't work correctly (sorry, not sure the actual term... when you type an object and hit . and the list of properties and methods shows to select from)
The behavior is that when I hit ., the list popups up for a fraction of a second and then closes. It happens so fast I try to do a quick Backspace, ., Backspace, . cycle a few times to at least see the name I need, but I usually cant' get it and end up having to find the exact name elsewhere from code. Extremely irritating...
It happens sporadically with no real pattern I can find. Here's patterns that I've ruled out:
The file that's open doesn't seem to matter.
Whether or not I close/reopen the file doesn't seem to matter
Whether I navigate to another file and back doesn't seem to matter
It will work/not work multiple times on and off throughout the same file
It doesn't seem to be relevant to any particular object/property/method
I've checked all my options (there doesn't seem to be Text Editing options for Razor?), have tried clearing caches, the reloading solution/projects, restarting VS, all of which seem to still provide no pattern.
Has anyone come across this and have any ideas of where else I can look to fix it?
Example
Here's an extremely simple example... new project, very little code/files, very simple view. Where the Model. stops, I should have the usual base methods, and an 'Items' collection. It pops up for a split second then disappears... no lambdas/complex view parsing involved (this is reproducible as well):
Update: Patterns
Things I've noticed:
If I'm entering a #model ns.ns.ns.type, it rarely happens toward the "base" end of the namespaces. It's as I get further towards the type that it happens. This one is intermittent.
In some cases, it works perfectly fine, every single time. For example, I often use DevExpress tools, and have never seen the behavior on any of their extensions (so, #Html.DevExpress(). (and other similar, not necessarily DevEx models) will never cause a problem)
It happens almost all the time when I'm accessing my #Model (which is where I most want it!). I've found some cases where this is reproducible every time (see above example), but it's about 90%+
Occasionally, as I work through the object tree, one will fail while the next works (ex: #models ProjName.Web.App.Subscriptions.Models.AccountCreateVM... it might fail on Subscriptions but work fine on Models)
Occasionally, beginning to type the name within autocomplete kicks it back into gear and it starts working again. In the above example, starting to type Acc for AccountCreateVM causes it to start working again.
I haven't found the root cause, but in all cases, CTRL+SPACE works. This isn't the best, but light years better than nothing at all.
(this shortcut is not one I've used in the past, so this is likely standard behavior, but...) If you're at the dot Model. and autocomplete list disappears, CTRL+SPACE consistently brings it back up, and when it does come back, it stays! If there's only one possible autocomplete member, it'll auto-fill the member for you upon CTRL+SPACE
This happens for me all throughout VS2015 during lambda statements.
It happens when editing code "mid-document", as in, if there is anything besides a ) or } following where I'm typing. VS appears to be struggling to tell where the current statement ends & the next statement begins.
The following code will consistently fail to trigger Intellisense at the period, even when explicitly invoked.
var subset = initialSet.Where(x => x.
var result = new Whatever();
In Razor, it is very common to be editing code between existing text and using lambda statements:
<strong>#Html.DisplayFor(m => m.</strong>
This is probably why you only experience this in Razor.
The way I work around this bug is just to write the ) to close the method.
var subset = initialSet.Where(x => x.)
var result = new Whatever();
<strong>#Html.DisplayFor(m => m.)</strong>
Intellisense can then be triggered on the period.
If you're using a method that requires a minimum of more than just the lambda (like RadioButtonFor), you'll also need to put in a comma for each of the extra parameters.
<strong>#Html.RadioButtonFor(m => m.,)</strong>
If Intellisense is appearing, but immediately disappearing again, the best solution I've found so far is to just type a few letters of any known member, then using Ctrl-Left to skip back to the period, and trigger Intellisense again (Ctrl-Space or backspace-retype). This usually gets it to appear and stay. You'll have to delete the characters you typed afterwards, which can be frustrating.
Just make sure the ) does not touch the text you are editing, and the popup will stay up.
Instead of...
#Html.Partial("ManageGrid", Model.)
Use...
#Html.Partial("ManageGrid", Model. )
The intellisense seems to get confused by touching close parenthesis. Not ideal, but this was the only way I could get it to work for me consistently.
In my specific case, i was able to solve the problem by installing the latest version Microsoft ASP.NET and Web Tools.
https://marketplace.visualstudio.com/items?itemName=JacquesEloff.MicrosoftASPNETandWebTools-9689
Once I installed it, the problem was gone. It is likely that this update fixed something that could be fixed with an older version, but either way I'm happy.
(I found this in Visual Studio under Tools->Extensions and Updates...->Updates->Visual Studio Gallery)
I had the same error and I fixed it by deleting all the files of the component model cache.
This is the path:
Users\YourName\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
Hope that helps
I use ctrl+j as a temporary solution when I know the content.
Or keep writing without right parenthesis can use the completion:
#Html.LabelFor(m => m.Name
Whenever this annoying thing happens to me, I just put an extra dot and then it works. I have to put the extra dot every time. For example, if I write this and intellisence flashes and disappears:
#Html.TextBoxFor(m => m.
then I just do this:
#Html.TextBoxFor(m => m..
And intellisense will now show after first dot. I have made this a habit until MS has a fix for it.
Instead of...
#Html.Partial("ManageGrid", Model.)
Use...
#Html.Partial("ManageGrid", Model.

console logging in google chrome

I am writing a Google Chrome Extension and trying to make the transition to coding in HTML, CSS and Javascript from the kind of coding I did 40 years ago. It's a big learning curve but a little bit of console logging would help a lot. (Who remembers the green phosphor displays on the old iron-core memory Sperry Univacs? Now there was a console that could tell you what was going on - mount a tape, change a diskpack or put more paper in the printer.) But I digress.
Just a few days ago, I was able to send messages to the Google Chrome DOM Inspector console log from my content script or background page like this:
console.log="RECEIVED REQUEST FROM CONTENT SCRIPT PEEK.JS";
Later if I inspected the page where that code was injected, I would see that exact same message on the console. If that line executed four times, I would see four instances of that messages in sequence on the console. It was simple but beautiful.
Now, nothing appears on the console unless I type in "console.log" and in this case I see only the last instance of the message. What's the problem here? Did I toggle something off in the debugger? Am I writing the code wrong? Should it be: "console.log("Message Here");" - (this always returns an error) ?
I have spent literally hours trying to find the answer to this question and I can only surmise that the question is so simple that even a well-educated child could answer it. The alternative is to spend more hours trying to find my bugs thru implication or from alert messages. Better to spend my hours learning how to effectively use the inspector for debugging.
For example, yesterday after restructuring what was once working code so that it would pass an array to background from content instead of background requesting each item successively from content, the extension broke, as might be expected. The console displays one error message: "Error during tabs executeScript: Unknown error." with a link that says "chrome/ExtensionProcessBindings:95" on the far right of that same line. Obviously the error message is almost useless. Clicking on the link brings me to the resources panel which displays a blank frame to the right with the words "background.html" This appears to be useless as well.
How is this information at all helpful? It took me another six hours to figure out that I had moved a variable definition to another place in the code so that it was not defined at the time the executeScript line was executed. Had the error message said that a parameter was undefined in executeScript, I could have found it in about ten minutes.
So back to the original question - I WANT A SIMPLE ANSWER - don't tell me to write a function. I saw the console displaying what I wanted two days ago without writing any functions.
Here is your SIMPLE ANSWER: Instead of
console.log="RECEIVED REQUEST FROM CONTENT SCRIPT PEEK.JS";
You should use
console.log("RECEIVED REQUEST FROM CONTENT SCRIPT PEEK.JS");
For console.log():
https://developer.mozilla.org/en-US/docs/Web/API/console.log
I would recommend searching the Mozilla Developer Network for documentation on JavaScript and many browser technologies.
My general suggestion to help with mistyped or out of scoped variables is to use strict javascript:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode
This makes certain JavaScript idioms into errors which are detected earlier, and which give more helpful diagnostics. (The quick version is to put the single line "use strict"; at the top of your js files, or if that causes to many problems you can put it as the first line inside any function to do function-by-function migration.)
The reason why console.log = blah would show blah on the console in some situations is that in JS, <left side> = <right side expression> is an expression which evaluates to the same value as just <right side expression>, but it has the side affect of also assigning to <left side>. (This is similar to C assignment expressions.)
Then, in the context you were in, the console will display the result of any expression evaluation. This is different from explicitly calling console.log() which will display the arguments as the intended side effect of that function.
So in that case you were overwriting the standard console.log function with a string, and the entire expression evaluates to that string value, and the console's builtin behavior (not the console.log() function!) would display the result of your evaluation.
In JS most things are mutable, and you can overwrite all kinds of fields and variables, so be aware of this potential gotcha!
Also, a general recommendation for seeking help on the web:
For sites like StackOverflow is to limit your post to a very specific single question. This is because people with similar problems will come here based on web searches or other links, and they need to figure out if this page helps them with their particular problem quickly. If they have to read through paragraphs with multiple questions or anecdotes, this really slows them down. I would guess that's why this question has been downvoted.
If you have multiple questions, make separate posts. StackOverflow isn't a good site for anecdotes about your experience in the past. FWIW- I personally found your background as a programmer on 70's era machines interesting, but many readers may get lost in the details. Those kinds of anecdotes could make a good blog post.