Skip to content

Commit

Permalink
First step at the Visualforce Language Server (#151)
Browse files Browse the repository at this point in the history
* Bring in the original Microsoft overall HTML language server
* Embed the HTML extension client into our visualforce extension
* Rename visualforce package to next

@W-4344488@
  • Loading branch information
vazexqi authored Oct 6, 2017
1 parent 74fc782 commit 76b8472
Show file tree
Hide file tree
Showing 83 changed files with 14,054 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,42 @@
"outFiles": ["${workspaceRoot}/packages/*/out/**/*.js"],
"preLaunchTask": "Compile"
},
{
"type": "node",
"request": "launch",
"name": "Launch Salesforce DX Visualforce Language Server Tests",
"program":
"${workspaceRoot}/packages/salesforcedx-visualforce-language-server/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
"--recursive",
"${workspaceRoot}/packages/salesforcedx-visualforce-language-server/out/test"
],
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/packages/*/out/**/*.js"],
"preLaunchTask": "Compile",
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"request": "launch",
"name": "Launch Salesforce DX Visualforce Markup Language Server Tests",
"program":
"${workspaceRoot}/packages/salesforcedx-visualforce-markup-language-server/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
"--recursive",
"${workspaceRoot}/packages/salesforcedx-visualforce-markup-language-server/out/test"
],
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/packages/*/out/**/*.js"],
"preLaunchTask": "Compile",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "Launch Salesforce DX VS Code SLDS Linter Tests",
"type": "extensionHost",
Expand Down
27 changes: 27 additions & 0 deletions packages/salesforcedx-visualforce-language-server/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2017, Salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

* Neither the name of Salesforce.com nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 changes: 31 additions & 0 deletions packages/salesforcedx-visualforce-language-server/OSSREADME.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{
"name": "microsoft/vscode",
"license": "MIT",
"licenseDetail": [
"MIT License",
"",
"Copyright (c) 2015 - present Microsoft Corporation",
"",
"Permission is hereby granted, free of charge, to any person obtaining a copy",
"of this software and associated documentation files (the \"Software\"), to deal",
"in the Software without restriction, including without limitation the rights",
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell",
"copies of the Software, and to permit persons to whom the Software is",
"furnished to do so, subject to the following conditions:",
"",
"The above copyright notice and this permission notice shall be included in all",
"copies or substantial portions of the Software.",
"",
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR",
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,",
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE",
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER",
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,",
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
],
"version": "1.16.0",
"repositoryURL":
"https://github.com/Microsoft/vscode/commit/29c6578013ea1ab9d0d2d316364fc43496326fe5"
}
]
7 changes: 7 additions & 0 deletions packages/salesforcedx-visualforce-language-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Introduction

This is the top-level language server for supporting .page and .component files
for Visualforce. This borrows heavily from the Microsoft VS Code overall [HTML
language
server](https://github.com/Microsoft/vscode/tree/master/extensions/html) -- the
one that can handle a combination of JavaScript and CSS embedded within HTML.
45 changes: 45 additions & 0 deletions packages/salesforcedx-visualforce-language-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@salesforce/salesforcedx-visualforce-language-server",
"description": "Visualforce language server",
"version": "40.13.0",
"publisher": "salesforce",
"license": "BSD-3-Clause",
"engines": {
"vscode": "^1.15.0"
},
"dependencies": {
"@salesforce/salesforcedx-visualforce-markup-language-server": "40.13.0",
"vscode-css-languageservice": "2.1.9",
"vscode-languageserver": "3.4.2",
"vscode-languageserver-protocol": "3.4.2",
"vscode-languageserver-types": "3.4.0",
"vscode-nls": "2.0.2",
"vscode-uri": "1.0.1"
},
"devDependencies": {
"@types/mocha": "^2.2.38",
"@types/node": "^6.0.40",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"mocha-junit-reporter": "^1.13.0",
"mocha-multi-reporters": "^1.1.4",
"nyc": "^11.0.2",
"remap-istanbul": "^0.9.5",
"source-map-support": "^0.4.15",
"shx": "0.2.2",
"typescript": "2.4.0"
},
"scripts": {
"vscode:package": "npm prune --production",
"compile": "tsc -p ./ && shx cp -R test/fixtures out/test",
"lint": "tslint --project .",
"watch": "tsc -watch -p .",
"clean":
"shx rm -rf node_modules && shx rm -rf out && shx rm -rf coverage && shx rm -rf .nyc_output",
"test":
"./node_modules/.bin/nyc ./node_modules/.bin/_mocha --recursive out/test"
},
"nyc": {
"reporter": ["text-summary", "lcov"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See OSSREADME.json in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { TextDocument } from 'vscode-languageserver';

export interface LanguageModelCache<T> {
get(document: TextDocument): T;
onDocumentRemoved(document: TextDocument): void;
dispose(): void;
}

export function getLanguageModelCache<T>(
maxEntries: number,
cleanupIntervalTimeInSec: number,
parse: (document: TextDocument) => T
): LanguageModelCache<T> {
let languageModels: {
[uri: string]: {
version: number;
languageId: string;
cTime: number;
languageModel: T;
};
} = {};
let nModels = 0;

let cleanupInterval = void 0;
if (cleanupIntervalTimeInSec > 0) {
cleanupInterval = setInterval(() => {
const cutoffTime = Date.now() - cleanupIntervalTimeInSec * 1000;
const uris = Object.keys(languageModels);
for (const uri of uris) {
const languageModelInfo = languageModels[uri];
if (languageModelInfo.cTime < cutoffTime) {
delete languageModels[uri];
nModels--;
}
}
}, cleanupIntervalTimeInSec * 1000);
}

return {
get(document: TextDocument): T {
const version = document.version;
const languageId = document.languageId;
const languageModelInfo = languageModels[document.uri];
if (
languageModelInfo &&
languageModelInfo.version === version &&
languageModelInfo.languageId === languageId
) {
languageModelInfo.cTime = Date.now();
return languageModelInfo.languageModel;
}
const languageModel = parse(document);
languageModels[document.uri] = {
languageModel,
version,
languageId,
cTime: Date.now()
};
if (!languageModelInfo) {
nModels++;
}

if (nModels === maxEntries) {
let oldestTime = Number.MAX_VALUE;
let oldestUri = null;
// tslint:disable-next-line:forin
for (const uri in languageModels) {
const localLanguageModelInfo = languageModels[uri];
if (localLanguageModelInfo.cTime < oldestTime) {
oldestUri = uri;
oldestTime = localLanguageModelInfo.cTime;
}
}
if (oldestUri) {
delete languageModels[oldestUri];
nModels--;
}
}
return languageModel;
},
onDocumentRemoved(document: TextDocument) {
const uri = document.uri;
if (languageModels[uri]) {
delete languageModels[uri];
nModels--;
}
},
dispose() {
if (typeof cleanupInterval !== 'undefined') {
clearInterval(cleanupInterval);
cleanupInterval = void 0;
languageModels = {};
nModels = 0;
}
}
};
}
114 changes: 114 additions & 0 deletions packages/salesforcedx-visualforce-language-server/src/modes/cssMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See OSSREADME.json in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { getCSSLanguageService, Stylesheet } from 'vscode-css-languageservice';
import { Position, TextDocument } from 'vscode-languageserver-types';
import {
getLanguageModelCache,
LanguageModelCache
} from '../languageModelCache';
import { CSS_STYLE_RULE, HTMLDocumentRegions } from './embeddedSupport';
import { ColorInformation, LanguageMode, Settings } from './languageModes';

export function getCSSMode(
documentRegions: LanguageModelCache<HTMLDocumentRegions>
): LanguageMode {
const cssLanguageService = getCSSLanguageService();
const embeddedCSSDocuments = getLanguageModelCache<
TextDocument
>(10, 60, document =>
documentRegions.get(document).getEmbeddedDocument('css')
);
const cssStylesheets = getLanguageModelCache<Stylesheet>(10, 60, document =>
cssLanguageService.parseStylesheet(document)
);

return {
getId() {
return 'css';
},
configure(options: any) {
cssLanguageService.configure(options && options.css);
},
doValidation(document: TextDocument, settings: Settings) {
const embedded = embeddedCSSDocuments.get(document);
return cssLanguageService.doValidation(
embedded,
cssStylesheets.get(embedded),
settings && settings.css
);
},
doComplete(document: TextDocument, position: Position) {
const embedded = embeddedCSSDocuments.get(document);
return cssLanguageService.doComplete(
embedded,
position,
cssStylesheets.get(embedded)
);
},
doHover(document: TextDocument, position: Position) {
const embedded = embeddedCSSDocuments.get(document);
return cssLanguageService.doHover(
embedded,
position,
cssStylesheets.get(embedded)
);
},
findDocumentHighlight(document: TextDocument, position: Position) {
const embedded = embeddedCSSDocuments.get(document);
return cssLanguageService.findDocumentHighlights(
embedded,
position,
cssStylesheets.get(embedded)
);
},
findDocumentSymbols(document: TextDocument) {
const embedded = embeddedCSSDocuments.get(document);
return cssLanguageService
.findDocumentSymbols(embedded, cssStylesheets.get(embedded))
.filter(s => s.name !== CSS_STYLE_RULE);
},
findDefinition(document: TextDocument, position: Position) {
const embedded = embeddedCSSDocuments.get(document);
return cssLanguageService.findDefinition(
embedded,
position,
cssStylesheets.get(embedded)
);
},
findReferences(document: TextDocument, position: Position) {
const embedded = embeddedCSSDocuments.get(document);
return cssLanguageService.findReferences(
embedded,
position,
cssStylesheets.get(embedded)
);
},
findDocumentColors(document: TextDocument) {
const embedded = embeddedCSSDocuments.get(document);
return cssLanguageService.findDocumentColors(
embedded,
cssStylesheets.get(embedded)
);
},
getColorPresentations(document: TextDocument, colorInfo: ColorInformation) {
const embedded = embeddedCSSDocuments.get(document);
return cssLanguageService.getColorPresentations(
embedded,
cssStylesheets.get(embedded),
colorInfo
);
},
onDocumentRemoved(document: TextDocument) {
embeddedCSSDocuments.onDocumentRemoved(document);
cssStylesheets.onDocumentRemoved(document);
},
dispose() {
embeddedCSSDocuments.dispose();
cssStylesheets.dispose();
}
};
}
Loading

0 comments on commit 76b8472

Please sign in to comment.