Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plug-in] Need to implement "files.associations" configuration property #4581

Closed
vrubezhny opened this issue Mar 15, 2019 · 16 comments
Closed
Assignees
Labels
enhancement issues that are enhancements to current functionality - nice to haves vscode issues related to VSCode compatibility

Comments

@vrubezhny
Copy link
Contributor

vrubezhny commented Mar 15, 2019

https://code.visualstudio.com/docs/languages/identifiers

Configuration example:

"contributes": {
    "configurationDefaults": {
	'id': 'files',
	'type': 'object',
	'properties': {
		'files.associations': {
			'type': 'object',
			'markdownDescription': nls.localize('associations', "Configure file associations to languages (e.g. `\"*.extension\": \"html\"`). These have precedence over the default associations of the languages installed."),
		}
	}
}

https://github.com/Microsoft/vscode/blob/master/src/vs/platform/files/common/files.ts#L681

export interface IFilesConfiguration {
	files: {
		associations: { [filepattern: string]: string };
		exclude: glob.IExpression;
		watcherExclude: { [filepattern: string]: boolean };
		encoding: string;
		autoGuessEncoding: boolean;
		defaultLanguage: string;
		trimTrailingWhitespace: boolean;
		autoSave: string;
		autoSaveDelay: number;
		eol: string;
		hotExit: string;
		useExperimentalFileWatcher: boolean;
	};
}

It is impossible to install intelephense extension as Theia extension plugin because it requires a defined object (even an empty one is valid) to be returned when it requests for the associations preference in section files, otherwise, the following code (that is invoked when it's being activated):

vscode_1.workspace.getConfiguration('files').get('associations');

results into the following exception and failure:

PLUGIN_HOST(22186): initializing(/home/jeremy/projects/che/source/theia-ide/theia/packages/plugin-ext-vscode/lib/node/plugin-vscode-init.js)
PLUGIN_HOST(22186): PluginManagerExtImpl/loadPlugin(/tmp/vscode-unpacked/bmewburn.vscode-intelephense-client-1.0.8.vsix/extension/out/src/extension)

root INFO [nsfw-watcher: 22228] Started watching: /home/jeremy/projects/che/theia-runtime-workspace/.theia/phptest.php
root ERROR [hosted-plugin: 22186] (node:22186) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at workspaceFilesIncludeGlob (/tmp/vscode-unpacked/bmewburn.vscode-intelephense-client-1.0.8.vsix/extension/out/src/extension.js:125:31)
    at /tmp/vscode-unpacked/bmewburn.vscode-intelephense-client-1.0.8.vsix/extension/out/src/extension.js:74:72
    at Generator.next (<anonymous>)
    at /tmp/vscode-unpacked/bmewburn.vscode-intelephense-client-1.0.8.vsix/extension/out/src/extension.js:10:71
    at new Promise (<anonymous>)
    at __awaiter (/tmp/vscode-unpacked/bmewburn.vscode-intelephense-client-1.0.8.vsix/extension/out/src/extension.js:6:12)
    at activate (/tmp/vscode-unpacked/bmewburn.vscode-intelephense-client-1.0.8.vsix/extension/out/src/extension.js:29:12)
    at PluginManagerExtImpl.startPlugin (/home/jeremy/projects/che/source/theia-ide/theia/packages/plugin-ext/lib/plugin/plugin-manager.js:172:73)
    at PluginManagerExtImpl.$init (/home/jeremy/projects/che/source/theia-ide/theia/packages/plugin-ext/lib/plugin/plugin-manager.js:126:26)

root ERROR [hosted-plugin: 22186] (node:22186) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:22186) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

In order to run the intelephense in my local environment I've workarounded this issue with the following change, but for sure it can't be used in production:

$ git diff packages/plugin-ext/src/plugin/preference-registry.ts
diff --git a/packages/plugin-ext/src/plugin/preference-registry.ts b/packages/plugin-ext/src/plugin/preference-registry.ts
index fa74a71b..cb943256 100644
--- a/packages/plugin-ext/src/plugin/preference-registry.ts
+++ b/packages/plugin-ext/src/plugin/preference-registry.ts
@@ -100,7 +100,7 @@ export class PreferenceRegistryExtImpl implements PreferenceRegistryExt {
             get: <T>(key: string, defaultValue?: T) => {
                 const result = lookUp(preferences, key);
                 if (typeof result === 'undefined') {
-                    return defaultValue;
+                    return defaultValue ? defaultValue : {};
                 } else {
                     let clonedConfig: any = undefined;
                     const cloneOnWriteProxy = (target: any, accessor: string): any => {

Reference issues:
eclipse-che/che#12796
eclipse-che/che#12797
#1106
#4716

@akosyakov akosyakov added enhancement issues that are enhancements to current functionality - nice to haves vscode issues related to VSCode compatibility labels Mar 15, 2019
@tsmaeder
Copy link
Contributor

"files.associations" is documented as a VS Code preference here: https://code.visualstudio.com/docs/getstarted/settings

@tsmaeder
Copy link
Contributor

I see two problems here:

  1. There is no default preference "files.associations" in Theia, so I guess we should add it.
  2. What preference in Theia is used instead to associate files with languages? We need to do some adaptation in order to make this work.

@tsmaeder
Copy link
Contributor

In a first step, let's add the preference key and find out whether there is more work that we need to do.

@akosyakov
Copy link
Member

I believe it was not fixed and an incomplete solution was merged on master, i.e. there is a confusing preference now which does not change anything. This preference should affect editors in order a PR to be merged. @tolusha Please revert if you are not going to submit the rest today and reopen with complete solution.

@akosyakov akosyakov reopened this Mar 26, 2019
@tolusha
Copy link
Contributor

tolusha commented Mar 26, 2019

@akosyakov
Sorry, I might misunderstood something.
What does complete solution means?

@benoitf
Copy link
Contributor

benoitf commented Mar 26, 2019

AFAIK step1 is done as announced. Also it's great to see that php VS Code extension could run as well.
IMHO there is no clear definition of "incomplete" or "done". Master should allow multiple-steps work as long as it doesn't break features.

@akosyakov
Copy link
Member

akosyakov commented Mar 26, 2019

@benoitf @tolusha #4716 it is a new bug introduced by #4713, it is a definition of not done to me

@tsmaeder
Copy link
Contributor

To quote myself (hehe):

In a first step, let's add the preference key and find out whether there is more work that we need to do.

So is there more to do, @tolusha?

@tsmaeder
Copy link
Contributor

@benoitf @tolusha #4716 it is a new bug introduced by #4713, it is a definition of not done to me

I would argue that this is not really a regression, since the preference was never honored anyway, correct?

@akosyakov
Copy link
Member

I would argue that this is not really a regression, since the preference was never honored anyway, correct?

it is not a regression, true, just a new bug, before Theia does not provide this preference in UI anywhere, now it does, but does not support

@tolusha tolusha closed this as completed Mar 27, 2019
@tsmaeder tsmaeder reopened this Mar 27, 2019
@tolusha
Copy link
Contributor

tolusha commented Mar 27, 2019

How VS Code resolves language

There is a single location [1] where all associations stored. They come either from language registry [2] or from files.associations configuration property [3]. Language resolving comes to mimetype guessing [4] using registered associations where files.associations are prioritized.

How Theia resolves language

Basically it works the same. Through [5] it comes to [4] as well. So, basically adding files.associations to the file system preferences [6] and implementing something like [3] should help.

[1] https://github.com/Microsoft/vscode/blob/master/src/vs/base/common/mime.ts#L39
[2] https://github.com/Microsoft/vscode/blob/master/src/vs/editor/common/services/languagesRegistry.ts#L32
[3] https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/services/mode/common/workbenchModeService.ts#L169
[4] https://github.com/Microsoft/vscode/blob/master/src/vs/base/common/mime.ts#L109
[5] https://github.com/theia-ide/theia/blob/master/packages/monaco/src/browser/monaco-editor-model.ts#L86
[6] https://github.com/theia-ide/theia/blob/master/packages/filesystem/src/browser/filesystem-preferences.ts#L27

@akosyakov
Copy link
Member

There should not be dependencies between editor and filesystem extensions. It could be a tricky part. I think you can go ahead and implement, and then we can refactor it a bit together during review to break a dependency if it appears.

@tsmaeder
Copy link
Contributor

I'm not sure fixing this would introduce such a dependency. @tolusha could you explain how your fix would look? It's not obvious to me from looking at the references sources.

@tolusha
Copy link
Contributor

tolusha commented Mar 28, 2019

@tsmaeder
From my understanding we need entity to track files.associations changes and respectively update mimetype resolver [1]

[1] https://github.com/Microsoft/vscode/blob/master/src/vs/base/common/mime.ts#L109

@tsmaeder
Copy link
Contributor

That points to VSCode. Where does this code live in Theia, @tolusha ?

@akosyakov
Copy link
Member

akosyakov commented Mar 28, 2019

It should already be in Monaco. It would be nice introduce something like MimeService stub class in core extension, implement and rebind in Monaco extension (with exposing minimal API surface from mime.ts), and use in the filesystem extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement issues that are enhancements to current functionality - nice to haves vscode issues related to VSCode compatibility
Projects
None yet
Development

No branches or pull requests

5 participants