Skip to content

Commit

Permalink
Merge pull request #140 from mkslanc/extralib-ts
Browse files Browse the repository at this point in the history
Fix: extralibs path resolve
  • Loading branch information
mkslanc authored Sep 16, 2024
2 parents f49ab1a + b5b0959 commit 9f8b9e5
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
23 changes: 13 additions & 10 deletions packages/ace-linters/src/services/typescript/typescript-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,21 @@ export class TypescriptService extends BaseService<TsServiceOptions> implements
}

$getDocument(fileName: string): string | undefined {
let text: string;
let document = this.getDocument(fileName);
const fileNameWithoutUri = fileName.replace("file:///", "");
let document = this.getDocument(fileName) ?? this.getDocument(fileNameWithoutUri);
if (document) {
text = document.getText();
} else if (fileName in libFileMap) {
text = libFileMap[fileName];
} else if (fileName in this.$extraLibs) {
text = this.$extraLibs[fileName].content;
} else {
return;
return document.getText();
}
if (fileName in libFileMap) {
return libFileMap[fileName];
}
if (fileName in this.$extraLibs) {
return this.$extraLibs[fileName].content;
}
if (fileNameWithoutUri in this.$extraLibs) {
return this.$extraLibs[fileNameWithoutUri].content;
}
return text;
return;
}

getScriptKind?(fileName: string): ts.ScriptKind {
Expand Down
19 changes: 17 additions & 2 deletions packages/demo/docs-example/typescript-example.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/demo/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ export function createEditorWithLSP(mode, i: number, languageProvider: LanguageP

let options = mode.options ?? {};
languageProvider.setSessionOptions(editor.session, options);


/**
* Sets the file path for the current editor session.
* This allows the language provider to associate the editor session with a specific file path,
* which can be useful for features like code formatting, diagnostics, and other language-specific functionality.
*/
if (mode.filePath) {
languageProvider.setSessionFilePath(editor.session, mode.filePath);
}

closeButton.onclick = () => {
languageProvider.closeDocument(editor.session);
Expand Down
27 changes: 24 additions & 3 deletions packages/demo/webworker-lsp/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ let modes = [
{name: "css", mode: "ace/mode/css", content: cssContent},
{name: "less", mode: "ace/mode/less", content: lessContent},
{name: "scss", mode: "ace/mode/scss", content: scssContent},
{name: "typescript", mode: "ace/mode/typescript", content: typescriptContent},
{name: "typescript", mode: "ace/mode/typescript", content: typescriptContent, filePath: "someLibDir/index.ts"},
{name: "python", mode: "ace/mode/python", content: pythonContent},
/*{name: "svelte", mode: "ace/mode/html", content: svelteContent},
{name: "astro", mode: "ace/mode/astro", content: svelteContent},
{name: "golang", mode: "ace/mode/golang", content: svelteContent},*/
{name: "typescript", mode: "ace/mode/typescript", content: typescriptContent1},
{name: "typescript", mode: "ace/mode/typescript", content: typescriptContent1, filePath: "anotherFile.ts"},
{name: "javascript", mode: "ace/mode/javascript", content: jsContent},
{name: "tsx", mode: "ace/mode/tsx", content: tsxContent},
{name: "jsx", mode: "ace/mode/javascript", content: jsxContent, options: {jsx: true}}, //TODO:
Expand All @@ -57,9 +57,30 @@ languageProvider.setGlobalOptions("json", {
languageProvider.setGlobalOptions("typescript", {
errorCodesToTreatAsWarning: [
"2540"
]
],
extraLibs: {
"libDeclaration.d.ts": {
content:
`declare class ChainableOne {
chainableTwo: ChainableTwo;
setAlpha(value: string): this;
setBeta(value: number): ChainableTwo;
}
declare class ChainableTwo {
setGamma(value: boolean): this;
addAlpha(value: string): ChainableOne;
}`,
version: 1
},
"dir/file.ts": {
content: "export var data = new ChainableOne();",
version: 1
}
}
});


languageProvider.setGlobalOptions("javascript", {
errorMessagesToTreatAsInfo: [
/Identifier\sdirectly/
Expand Down

0 comments on commit 9f8b9e5

Please sign in to comment.