Dynamically register a language - vscode-extensions

I'm writing a vscode extension and I'd like to register languages dynamically, based on user configuration. The extension would then instantiate LSP clients to talk to servers derived from user configuration as well.
This would allow for people writing custom and toy languages to get an extension "for free" and experiment with editor features without necessarily having to implement and publish the vscode part of it.
I've dug a bit in the vscode sources, and found an interface that seem like it could help : "ILanguageService", but I'm unsure as to whether this is something that's accessible from the extension API.
Any idea how I could go at it ? Is it even possible ?

Alright, so my question stemmed from a misunderstanding of how LSP clients work. They don't necessarily need to be tied to a language, and can work on a glob-pattern basis, something like
const filter: DocumentFilter = {
scheme: 'file',
pattern: `**/*.${myLanguage.extension}`
};
const clientOptions: LanguageClientOptions = {
documentSelector: [filter]
};
This seems to be sufficient for vscode to understand which LSP it should be calling

Related

How to list the exposed members of a package/dir-like method in Elm?

I have been searching the official docs and existing questions and could not find any information on this - in Elm, how it would be possible to see the members/methods/variables that belong to or are exposed by a package in Elm, (such as the dir method in python), without having to dive into the source code each time?
What I want to do is get a simple list of what methods are exposed by an imported package. (So for a package like List, it should output reverse , all, any, map, etc.) I have attempted tab completion in elm repl and the elm extension available in VS code editor, and elm repl does not offer any methods such as help, doc, ?, dir, man, etc., so I have no idea where to even start. I'm wondering how everyone else does this other than pulling up the source code for each and every package they use.
I apologize for the newbie question and if I misread or have been missing anything, but I couldn't even find anything in the https://elmprogramming.com tutorial. Thanks in advance.
Nothing like this exists in Elm to do reflection over modules, unfortunately (as of 0.19.1, at least).
However, if you aren't looking to actually do this kind of thing at runtime, but rather as a convenient way of finding out for development, the elm packaging system enforces the requirement that all public functions are documented, so if you visit the package page, every public function and type will be documented there (obviously it can't enforce the content of the documentation, but at the very least it will be listed).

Creating Cytoscape.js extensions

Max, I want to update my extension to the new format, but I am running into issues with placement of custom code. It seems that the extension framework has been updated a lot since I added an extension 4 years ago. Is there a way to get better documentation on getting started with adding a extension? I am happy to help write up the documentation if you can help answer some questions that I think would help get people started. Let me know.
The only thing that really changed is that the scaffolder creates a webpack project for you. The extension registering procedure is the same: http://js.cytoscape.org/#extensions/api
For example, cytoscape( 'collection', 'fooBar', function(){ return 'baz'; } ) registers eles.fooBar().
I guess the main thing is that there are a lot more files than what the previous scaffolder generated, so it might be harder to find things. The layout output has lots of files, because it creates a skeleton impl for each of the continuous case and the discrete case.
The scaffolder isn't strictly necessary. You could use another build system (or none at all) as long as you call cytoscape(). For example, if you only care about publishing to npm for people who use webpack/browserify/rollup, then you could just use cjs require('cytoscape') to pull in the peer dependency. Exporting a register function is nice if you want to allow the client to decide the order of extension registrations with cytoscape.use(extension) (or extension(cytoscape)).
You're right that there should be some more docs on the output of the scaffolder. Maybe a summary of the files would suffice. We could add a tutorial in the blog later if need be. Both the docs and the blog just use markdown, so the content could go in either place.

Any alternative to shim feature provided in Microsoft fake framework?

I am wondering is there any alternative lib to the shim feature provided in Microsoft fake framework since it is only supported in ultimate version?
There are three frameworks to my knowledge that allow you to mock non virtual methods and sealed classes like Fakes' Shims. There are
Microsofts' Moles or Fakes
Teleriks JustMock
TypeMocks
They are all commercial because they use the Profiling API, which is very hairy and poorly documented, so coding them is a real pain.
And for the record I'm all for fakes. Most code that people are working on is legacy code. One of the Pragmatic Programmer's rules of refactoring is make sure that you have unit test coverage before any refactorings to avoid regression. This makes Fakes and similar frameworks super useful, especially when the legacy code was not written for test-ability.
Prig hasn't been updated to work with VS 2017, but Pose does, and works really well for what I needed it for (basic shimming of Environment.UserName, and DateTime.Now and similar), and has a really nice interface:
// Create shims. They only apply within this isolate block.
var dateTimeShim = Shim.Replace(() => DateTime.Now)
.With(() => new DateTime(2010, 1, 1));
var usernameShim = Shim.Replace(() => Environment.UserName)
.With(() => "john.wick");
// Shims are only active within an Isolate block - and you
// have to pass all shims you want to be active.
PoseContext.Isolate(() =>
{
// Run your test - shims are active at this point.
RunTest();
}, dateTimeShim, usernameShim);
EDIT
I should note that I get lots of errors when doing fairly basic tests - really scary errors like "Common Language Runtime detected an invalid program.", and "JIT Compiler encountered an internal limitation." so caveat emptor.
An open source alternative is Prig. MIT licenced and still active - but slightly behind with VS IDE

how to get knowing more about a class behaviour without looking at its manual?(a fundamental question about how to dive more into OOP)

I'm practicing OOP for 2 years (for real) and I know how to consume objects and packages and I'm developing stuffs mostly using C# .
but I have a problem with consuming unknown objects and packages as an instance :
for now I am working on an enterprise like website and for part of our job we need to consume RSS. I decided to use "System.Xml.Xpath"
and my real problem is:
for using system.xml.xpath I should look at manual and read it carefully and I don't want to do that every time.A plain example of that is like following code :
XPathDocument xp = new XPathDocument(sites[2]);
XPathNavigator nav = xp.CreateNavigator();
XPathNodeIterator it = nav.Select(xpath3);
foreach (XPathNavigator n in it)
{
//get elements here
}
//another way of iterating elements is
while(it.movenext())
{
//it.current.Value;
}
for the "foreeach" part I got it from MSDN manual and I guess I could get this simple fact by looking at class structure.
but I don't know which structure I should look.
I know how to read tooltips and I'm familiar with things like : [] / collection / enum /generic / Ienumerable / Idisposable etc...
but I think there is something about reading class behaviors and I'm missing that part.
for make it more lucid :
I know whenever we have a class that inherited from IEnumerable so we can use foreach statement against that class to iterate it through
my real problem is I think classes are self described enough to not to look at manuals all the time but I don't know how/where to read those descriptions of classes so I need your advice to get more familiar with how to reading classes without looking at manuals.
best regards.
Classes can (and should) be documented with source code comments, and in many languages you can generate API documentation from these comments (in HTML, XML or other format). In Java it is called Javadoc; I don't know the C# term. If this is what you call "manual", then this is your primary source of information. Other than reading the source code comments and the code itself (which you often don't have access to, especially in the MS universe). If you don't find enough information in the API documentation, you can always try googling for more explanation, tutorials or usage examples.
Hope this helps; I am not entirely sure I understood your question though. If this is not the answer you are looking for, please clarify.

Has anyone created any cool rules for FxCop/StyleCop?

I'm just looking for some inspiration. Especially in the area of performance and security, naming conventions are important but not as 'cool' ;)
Even if your rule was only applicable to your domain/project but demonstrates how powerful a rule can be, please let me know.
I work with C#, but I'm interested in rules for any language.
In my experience, the developers that have started out creating custom rule sets for FxCop, usually give up after pulling out much hair. It seems like a great idea, but the pain is just not worth the effort.
An alternative to the mess of writing FxCop custom rules would be to use the commercial tool NDepend. With this tool one can write Code Rule over LINQ Queries (namely CQLinq). Disclaimer: I am one of the developers of the tool
More than 200 code rules are proposed by default, these include naming conventions, design, architecture, code quality, code evolution, dead code, .NET Fx usage...
CQLinq is dedicated to write code rules that can be verified live in Visual Studio, or that can be verified during build process and reported in an HTML/javascript report.
The strength of CQLinq over FxCop API or other tools, is that it is straightforward to write a code rule, and get immediately results. Facilities are proposed to browse matched code elements. Concretely this looks like that:
I've got a nice functioning base with 2 rules so far at breusable.codeplex.com under the fxcop directory
ConfigKeyExistsInConfig (make sure that any references to ConfigurationManager with a magic string key actually exists in the config file.
NoUnderscoresInProperties
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.FxCop.Sdk;
namespace RulesByImaginaryDevelopment
{
public class NoUnderscoresInProperties : BaseRule
{
public NoUnderscoresInProperties() : base("NoUnderscoresInProperties") { }
public override ProblemCollection Check(Member member)
{
var prop = member as PropertyNode;
if(prop==null)
return Problems;
if(prop.Name.Name.Contains("_"))
{
Problems.Add(new Problem(new Resolution("Remove any '_' from name "+prop.Name.Name)));
}
return Problems;
}
}
}
Also http://msdn.microsoft.com/en-us/magazine/cc163930.aspx