Language Service: Is there a way to force parsing? - languageservice

I am working on a language service and would like the parsing after the user types code to be faster.
Right now I rely on the ParseReason.Check and OnIdle mechanism that's documented on MSDN, but its often called a long time after the user has typed code. Sometimes it helps to move the cursor to another line to trigger it faster.
What I'd like to do is to force parse the file after I detect the user has typed in the file. I'm able to detect when the user is typing, but I don't know how to trigger the parser with a ParseRequest.

I was running into a similar problem, I wanted to scan files not opened in VS. The best I could do was to abstract out my parse functionality so it gets called by VS, but also called by another internal function to my extension whenever I desired without going through VS, and this would store my parse results to the same structures as the direct VS call on ParseRequest.
I'd be curious to know if you find a better way of doing it though.

You could try calling BeginParse() on your Source implementation. That creates a ParseRequest with the Check parse reason. I turned off the OnIdle timer in my language service and tested it out and it appears to work.
If your code that detects user key-presses has access to an instance of your LanguageService implementation, then you can use service.GetSource(...).BeginParse(). If it has access to the Source itself, then it's even easier.

Related

Language Server Protocol: find all methods

I am exploring LSP to get a feel for what it can do. Most things are pretty obvious, completion, find references, etc. I've been told that LSP will allow me to find all functions/methods in a given language but I've yet to figure out how that might be possible. After much searching and doing some investigations with a few languages in Emacs, I am starting to doubt that it is even possible. Am I missing something? Is it possible with a given LSP instance to find all methods by file, line and column location?
You would use the workspace symbol functionality. If you look in the "vscode-languageserver-protocol project, it says:
/**
A request to list project-wide symbols matching the query string given
by the WorkspaceSymbolParams. The response is
of type SymbolInformation[] or a Thenable that
resolves to such.
*/
LSP Documentation on Workspace
If you're using a client, you'd find the method that calls that. In the project I'm trying to do, using the Brackets.io client, the method is
client.requestSymbolsForDocument
for example. If you're writing your own client, then you'd implement the appropriate method. You may get some extra help here. For all functions in the current document, then look at document symbols.
That's about as I know, I'm also learning.
Good luck.
Sethmo

Storing and retrieving files in Blockly Web

I want to use Blockly to do some calculations, and then generate text files (as opposed to exporting code to JavaScript, Python, PHP, etc.)
I can’t see an obvious way to create my own blocks to do this in Blockly, so using AppInventor (Version: nb168), I got storing and retrieving files to work, in a crude test app on my Android tablet.
In AppInventor/Designer mode, clicking Storage/File creates a “Non-visible component for storing and retrieving files. Use this component to write or read files on your device.”
Then, in AppInventor/Blocks mode, clicking the “File1” icon gives access to 7 “file type blocks”, e.g. AppendToFile, Delete, ReadFrom, SaveFile, etc.
Is it possible to create similar “file type blocks” to use in Blockly Web?
I have limited programming knowledge, so would appreciate simple answers, please.
Thanks, Pete.
Andrew N Marshall from Google/Blockly has told me this:
"This is absolutely possible ...as long as you willing to work within the browser's security restrictions. The resulting files will be need to be manually "downloaded" one at a time, rather than written directly to the user's file system.
... I would start understanding what JavaScript functions are available to you. Attempt to construct a string and save it via a download dialog...
That means the "file" contents are really just a string in memory, a JavaScript variable. We have lots of "Text" blocks that can do a variety of operations on strings. If those are enough, you'll only need one new block to identify the string variable and initiate the download process.
Otherwise, you'll need to think about what blocks you want, and how they operate. They may operate on a specific variable in the JavaScript VM, not necessary exposed as a variable to Blockly.
Either way, you'll need to learn how to create a block and a Blockly app. We have a code lab that will walk you through all the steps. You'll learn how each block generates a string of code, and in your case, that code will be related to the download code I mentioned earlier."
So I'll press on - I just wanted to be sure my goal is actually achievable before I started.
Thanks, Pete.

waiting for the website to change something

I am a student and in the school website, what I want to do is that I want to busy wait on the certain URL and check if the class i want to register for is open or not. I was wondering if there was a way to constantly check on the website(busy waiting or otherwise) to see if the class is open or not. There is a table Rem where it shows the number of places remaining in the User Interface.
Also what language would you use to solve this problem?
Yes you can. but for that you will probably need to create a script that fetches the value of data from that table.
So something like web scraping should work.
I would definately use php for this stuff.
Google web scraping and you can code the script.
I am not sure if this is the exact thing that will help you, but what you need to do is something similar - See Here

Javascript override Request.Form("foo") for security (XSS)

I've got some source code that has some cross site scripting vulnerabilities in it. There is no input validation that happens when the browser sends data over to the server which is executing server-side Javascript and classic ASP (IIS 7.0).
My question is, is there a way to override the Request.Form("foo") object/method so that I can call a sanitization function too and get rid of prohibited JS/HTML? I don't want to do a find and replace on every single file everywhere Request.Form is called. I was hoping for something more elegant.
Any suggestions are appreciated.
I don't think you can change Request.Form members.
What you can do, as a partial solution, is to create a code that will run first on every page (for example, using an include directive) which loops over Request.Form, Request.QueryString etc., and if it finds suspected code, it terminates the code execution (Response.End). This solution is partial because it doesn't really sanitize input, it just drops execution when it finds suspected text.
Another option: Create an array, parallel to Request.Form. Populate this array with the same members as in Request.Form, but this time sanitized. Then, quickly do a Find-and-Replace over your whole code base, and change Request.Form to your custom array variable.
There is a way to replace the whole Request object with another COM object but its an insane solution and it would still require that all ASP files that use Form contain a common top include file. Its not possible to replace the Request object or one of its members globally at the application level.
The correct solution to the problem, your statement "don't want to do a find and replace on every single file everywhere" notwithstanding, is to perform such global replace.
Despite the number of .asp files that exist the cost is no more than knocking up a simple program to open each ASP file in a folder tree, adding an include line and replacing Request.Form.

How to write text values in masked field?

i need some help related to masked field in web form. Syntax of phone field is (___)___-_____, if i execute this code in ruby shell
browser.text_field(:id => 'txtphone').set '7893457889'
... nothing has been added in the phone field.
then i find this solution in one blog, someone said first unmask this field using this code.
browser.text_field(:id,'txtphone').fire_event("unmask")
then write the above code again.
browser.text_field(:id => 'txtphone').set '7893457889'
but still nothing has happened. kindly help me out...am i doing right or still there is a mistake.
If you could provide some sample of the page HTML it will be easier to give you an answer more likely to work.
Given what you have provided us to work from, we have to go with the normal way that such masked input fields typically work and go from there. Usually pages with this kind of thing are calling a javascript function which is triggered by a specific event. Most often this is an event such as onchange but it may be something like keypress or any other even that happens when a normal user types or pasts text into the cell.
You likely need to experiment with using the '.fire_event' method to fire the proper javascript event, or if that fails entirely making a direct call to execute the proper script
When doing this do not confuse the name of a script such as 'applymask' or somesuch with the javascript event which causes that script to be invoked.
The answers to this question How to find out which JavaScript events fired? include some good information on how to use firebug or the chrome developer tools to figure out what events are being fired when you interact with an object on the browser screen.
Update: instead of responding here to indicate if this answer was of any use the OP reposted their question here Masked Text Box issue and by digging around on the vendor's demo site (since that time he actually had posted some of the HTML when we asked for it) I was able to find a solution using watir-webdriver that worked for him.

Resources